entity framework 4 - Problem mapping one to many relationship with EF CTP4 -


i trying define 1 many relationship between category , project (a category can have 1 or many projects, project can have 1 or no category)

public class project : entity {      public virtual string title { get; set; }      public virtual guid? categoryid { get; set; }     public virtual category category { get; set; } }  public class category : entity {            public virtual string name { get; set; }     public virtual icollection<project> projects { get; set; } } 

i have defined following mappings:

            modelbuilder.entity<project>()             .mapsingletype(p => new {                 projectid = p.id,                 p.categoryid,                 p.title,                 p.slug,                 p.shortdescription,                 p.description,                 p.createdon,                 p.updatedon             })             .totable("projects");          modelbuilder.entity<category>()             .mapsingletype(c => new {                 categoryid = c.id,                 c.name,                 c.createdon,                 c.updatedon             })             .totable("categories");          // relationships         modelbuilder.entity<project>()             .hasoptional<category>(p => p.category)             .withmany()             .hasconstraint((p, c) => p.categoryid == c.id); 

now although appears working fine, ef still generating categories_products table (used many many associations).

i've disabled default database initializer yet table still being generated. doing wrong?

thanks ben

i removed project , category mapping code , let ef use default conventions create database. created relationship expected (one many between category , project).

i add reason explicitly defining mapping because ef not appear handle base classes well. had base class "entity" single property "id" entities inherited from. caused many problems ctp4 swapped interface ientity. still gave me constraints needed when working generic repository classes.

hopefully entity base classes better supported in rtm


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -