Click here to Skip to main content
11,703,632 members (67,775 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: .NET ADO.NET Framework database , +
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
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:
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  
Posted 23-May-12 2:11am

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

  Print Answers RSS
0 Maciej Los 570
1 OriginalGriff 500
2 Sergey Alexandrovich Kryukov 410
3 F-ES Sitecore 165
4 Andy Lanng 159
0 OriginalGriff 8,519
1 Sergey Alexandrovich Kryukov 7,667
2 CPallini 4,987
3 Maciej Los 4,686
4 Mika Wendelius 3,566

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100