code-first

Entities Framework 4 Code First: Inheritance

I am currently trialing EF4 code-first. My POCO classes inherit from an Audit class that contains CreatedBy, CreatedOn, UpdatedBy, UpdatedOn. I was hoping the framework would include the Audit properties in my Action table when creating my database, however this doesn't appear to be the case. Does anyone know how to enable this without o...

An Ajax accordion pattern in MVC

Hi, I am wandering what pattern to use for an area in my website that has several sub headings, which corresponding models. Say this is several parts of user data, which I have in several tables - like the ASP membership user table, a table with additional user information, and a table which may have several items to show for each user...

Using Entity Framework Code First CTP4 how to map an entity to multiple tables?

Using CTP4 and Code First, is it possible to map a single entity to two tables (using a 1-1 relationship between the two tables)? If so, how? MSDN: "How to: Define a Model with a Single Entity Mapped to Two Tables" http://msdn.microsoft.com/en-us/library/bb896233.aspx Related: http://stackoverflow.com/questions/3880237/mapping-data-...

Entity Framework Code First & Search Criteria

So I have a model created in Entity Framework 4 using the CTP4 code first features. This is all working well together. I am attempting to add an advanced search feature to my application. This "advanced search" feature simply allows the users to enter multiple criteria to search by. For example: Advanced Product Search Name Star...

how do i create a composite key that comprises a foreign key with code first?

I am using EF4 code first and want to generate a composite key which is made of a class property and foreign key. I have two classes: Order and Company. The Order class holds a reference but this will not necessarily be unique between companies. So I intend to use a composite key made up of Reference and Company.CompanyId. I have tried ...

Code First CTP4: How to map these two entities

Let's say that I have two entities, Team and Match. In every Match, there are two teams, the HomeTeam and the AwayTeam. A Team can have many matches, but HomeTeam and AwayTeam can only have one team each. Sometimes Team is a HomeTeam, and sometimes the same Team is an AwayTeam. I have provided just the basics for each of the classes: pu...

How to use .Top() with Code First

Is this possible with Code First? I could do this if I only used Entity Framework: var q = from m in context.Products .Top("0") select m; ...

Entity Framework CTP 4 - Code First Custom Database Initializer

I would like to implement a custom database initialization strategy so that I can generate the database schema and apply it to an EXISTING EMPTY SQL database using a supplied User ID and Password. Unfortunately the built-in strategies don’t provide what I’m looking for: // The default strategy creates the DB only if it doesn't exist -...

EF4 Object State Manager is claiming multiple entries are attached when there aren't

I am trying to add functionality in my ASP.NET MVC app to change some fields of my data structure. After clicking the submit button on the form, the following action is called: [HttpPost] public ActionResult Edit(Document doc) { // Attempt to save the project if (_documentService.SaveDocument(doc) == Service...

TPT mapping Entity Framework CTP4 behaving like TPH

I am writing my code as suggested, public class A { public int id {get;set;} public string Astring {get;set;} } public class B : A { public string Bstring {get;set;} } builder.Entity<A>().MapHierarchy( u=> new { ... }).ToTable("A"); builder.Entity<B>().MapHierarchy( u=> new { ... }).ToTable("B"); ... = I have all the pr...