Reputation: 31
My Solution consists of a different projects. I have a project for each of the contexts and project for a Base Context that all other context classes inherit for only referencing 1 database. I have 3 other projects for the different Domain Classes(Customer, Rental, Owner) that have the actual entities. Also I have 1 helper class that the Domain Classes have reference too.
My problem is when I right click on any of the context classes and select Entity Framework>View Entity Data Model(Read Only) I get the "Sequence contains no matching element".
Now I have seen a couple of posts about this being a issue if the project actually was within a Solution Folder and as soon as this has been placed on the Solution root it starts working. In my case it is a project on the root directory of the Solution. This is my first project using Entity Framework, so if I am being vague I apologize, I have not seen any solution for my problem so any help would be appreciated.
Upvotes: 3
Views: 2477
Reputation: 683
It may be as simple as having the SetInitializer on database being set to null, and EF needing to upgrade your DB.
Either in code:
Database.SetInitializer<TContext>(null);
or in config
<appSettings>
<add key="DatabaseInitializerForType Namespace.Class, Assembly" value="Disabled" />
</appSettings>
Obviously the config is an assembly reference, the important bit is the 'value="Disabled"~.
This is normal practice so that EF doesn't accidentally drop your database when starting your app.
Upvotes: 0
Reputation: 35
I wrestled with this today as well. I also have separate projects for the domain objects (entities) and the EF model under solution folders. I finally got it working by first moving the project that contains the DbContext derived class and all its dependent projects out of the solution folder into the root.
Secondly, I needed to drop the default database that EF uses to create the model and it's metadata. It seems that when the power tool runs, it uses the default constructor of the class deriving from DbContext. In my case, that model was way out of date. I typically use an explicit connection string, so the default model hadn't been updated in a while. By default, EF will create a DB on the .\SQLEXPRESS instance, naming the DB after the class derived from DbContext.
Hope this helps,
Jeff.
Upvotes: 1