Click here to Skip to main content
15,075,492 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I need to map some auto generated classes, which I dont want to change for obviouse reasions (it's auto generated!).

So is there a possibility to define a Primary Key with fluent API of the Entity Framework (4.3 in my case)? Handling Attributes as ComplexType leads to DbUpdateExcetion due to NULL values. Adding a Primary Key to the generated classes may be a solution, but not suitable for me, POCOs must stay unchanged. Please help! Thanks.

Currently I am ignoring the Attributes because of the ModelValidationException
C#
EntityType 'Attribute' has no key defined.  Define the key for this EntityType. 
EntitySet 'Attributes' is based on type 'Attribute' that has no keys defined. 


here is a shortend sample code:
C#
public class Item 
{ 
   public ID {set;get;} 
   public Attribute[] Attributes {set;get;} 
}  
public class Attribute 
{ 
   public SomeComplexType misc1 {set; get;} 
   public SomeComplexType misc2 {set; get;} 
} 
 
public class ItemDb : DbContext 
{ 
    public ItemDb(string connection) : base(connection)  {} 
 
    public DbSet<Item> Items { get; set; } 
 
    protected override void OnModelCreating(DbModelBuilder builder) 
    { 
      // currently I am ignoring the Attributes  
        builder.Ignore<Attributes>(); 
    } 
} 
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900