How to in-code supply the password to a connection string in an ADO.Net Entity Data Model

When you create your context, you can set a connection string. To build this connection string, you can parse the connection string without the password with an EntityConnectionStringBuilder and then parse the inner connection string with an other ConnectionStringBuilder, depending on your browser. Then you can set the password and pass it to the constructor. … Read more

Entity Framework 4: Does it make sense to create a single diagram for all entities?

Having one big EDM containing all the entities generally is NOT a good practice and is not recommended. Using one large EDM will cause several issues such as: Performance Issue in Metadata Load Times: As the size of the schema files increase, the time it takes to parse and create an in-memory model for this … Read more

The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations

Entity Framework Code-First conventions are assuming that EntityA.EntityB and EntityB.PreferredEntityA belong to the same relationship and are the inverse navigation properties of each other. Because both navigation properties are references (not collections) EF infers a one-to-one relationship. Since you actually want two one-to-many relationships you must override the conventions. With your model it’s only possible … Read more

AutomaticMigrationsEnabled false or true?

Automatic migrations do all the magic for you but they don’t allow strict versioning (you don’t have special fixed migration for each version). Without strict versioning you cannot track version of your database and you cannot do explicit upgrades (you cannot do downgrades at all). If you don’t plan to use versioning where you need … Read more

Entity Framework Code First naming conventions – back to plural table names?

The RTM version of Code First will fully support a cool feature called Pluggable Conventions where you can add or replace the default conventions such as the one you mentioned. Fortunately, what you are looking for is already included in CTP5. You can switch off the pluralizing table names convention with removing PluralizingTableNameConvention convention. This … Read more

Entity Framework Multiple Object Contexts

@Danny Varod is right. You should use one ObjectContext for the whole workflow. Moreover because your workflow seems as one logical feature containing multiple windows it should probably also use single presenter. Then you would follow recommended approach: single context per presenter. You can call SaveChanges multiple times so it should not break your logic. … Read more

How to convert DbSet in Entity framework to ObjectQuery

I found the answer. Of course, it is possible to convert DbSet in Entity framework to ObjectQuery using the below lines of code. ObjectContext objectContext = ((IObjectContextAdapter)db).ObjectContext; ObjectSet<Request> objectSet = objectContext.CreateObjectSet<Request>(“Requests”); where, db – Context class inherting from DbContext. Requests – DbSet<Request> defined in Context class. objectSet – Can now be passed as ObjectQuery.

Change db table name in EF4 (entity framework 4)

If you just need to change the name of the table you can: Open EDMX file with XML Editor. Locate SSDL section in it. Locate entity set element for example <EntitySet Name=”Customers” EntityType=”ExampleModel.Store.Customers” Schema=”dbo” />. Add Table=”MyTableName” attribute. <EntitySet Name=”Customers” EntityType=”ExampleModel.Store.Customers” Schema=”dbo” Table=”MyTableName” /> Here is a complete CSDL, SSDL, MSL specification. Hope that helps.