LINQ To Entities + Include + Anonymous type issue

As Ladislav mentioned, Include only works if you select the Ticket entity directly. Since you’re projecting other information out, the Include gets ignored. This should provide a good work-around: var data = ctx.Set<Ticket>() .Select(p => new { Ticket = p, Clients = p.Client, LastReplyDate = p.Replies.Max(q => q.DateCreated) }); First of all, each Ticket’s Clients … Read more

Model First with DbContext, Fails to initialize new DataBase

This is wrong connection string. Once you are using model-first / database-first (EDMX) you must use Entity connection string with referencing .ssdl, .msl and .csdl metadata files. Also be aware that you must create your database in design time when creating model from EDMX = you must generate SQL script and execute it to create … Read more

How should I set up my integration tests to use a test database with Entity Framework?

Thanks so much to @Justin and @Petro for your answers, which have helped me immensely. The solution I have come up with is a combination of the techniques you suggested. The solution described below provides a new database for each run of the tests, and a separate transaction for each test. I added a connection … Read more

The relationship could not be changed because one or more of the foreign-key properties is non nullable

In Entity Framework you can work with foreign key associations. That is, a foreign key to another object is expressed as a pair of two properties: a primitive foreign key property (e.g. NominalRouting.OrderItemId) and an object reference (NominalRouting.OrderItem). This means that you can either set a primitive value or an object reference to establish a … Read more

Entity Framework Code First Using Guid as Identity with another Identity Column

This ended up working for me, Entity Framework 5. Turn off automatic migrations Migrate to create the initial table, no frills Declare the ClusterId as Identity (annotation) [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override int ClusterId { get; set; } Migrate Declare the pk property Id as Identity after the other one has been updated [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override Guid … 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