1
votes

I've created console application. Then I've performed Install-Package EntityFramework, setted target .net 4.0.

My simple model is

public class Abonent
    {
        public Abonent() {}
        [Key]
        public int AbonentId { get; set; }
        public string Name { get; set; }
    }

My dbcontext is (ModelContext.cs)

public class ModelContext : DbContext
    {
        public ModelContext():base(){}
        public DbSet<Abonent> Abonents { get; set; }
    }

Program.cs is

class Program
    {
        static void Main(string[] args)
        {

            Database.DefaultConnectionFactory = new System.Data.Entity.Infrastructure.SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
            ModelContext _abonentContext = new ModelContext();

            Abonent abonent=new Abonent();
            _abonentContext.Abonents.Add(abonent);
            _abonentContext.SaveChanges();
        }
    }

It works just fine, but when I do right button click on ModelContext.cs and choose Entity Framework -> Generate View and I get a message box saying "Exception has been thrown by the target of an invocation".

What I've done wrong? Is exist alternative for ef power tools? (VS 2010 SP1,Entity Framework Power Tools Beta 2)

2
I begin to experiment. If I delete App.config and packages.config that was added by executing Install-Package EntityFramework then Entity Framework Power Tools Beta creates pre-generated views, but when I run Main, then _abonentContext.SaveChanges(); invoke the exception "Error retrieving values from ObjectStateEntry. See inner exception for detail". Inner exception is "The mapping and metadata information for EntityContainer 'ModelContext' no longer matches the information used to create the pregenerated views". It means that trouble in standart App.config and packages.config - FunctorPrototype
Could anyone give me sample project with right generated view and setted references. Entity framework is powerful, but it takes about 15-25 seconds to process first add or query for context with 2-3 simple models. It is terrable!!! Is it really ef so slow and all face with this issue or I do something wrong? - FunctorPrototype

2 Answers

5
votes

I had this problem and solved it by Uninstalling Entity Framework Power Tools Beta 2 from the Tools -> Extensions and Updates menu.

I then restarted all visual studio 2012 instances and reinstalled it via the same menu option.

This resolved the issue on my end.

Good Luck.

-1
votes

problem may be you are using wrong version of Entity Framework.