Search code examples
c#.netentity-framework-4poco

EF4 POCO Many To One


I'm trying to have one POCO objects containing 2 tables.

I have 2 tables :

-Customer (#CustomerId, Name, CustomerProperties)
-CustomerExtended (#ExtendedId, #CustomerId, extendedProperties)

And I would have one POCO object:
Customer

- CustomerId
- Name
- CustomerProperties
- ExtendedProperties

Have you any idea?


Solution

  • This is code-first solution (without fluent code).

    public class Customer
    {
      public int CustomerId { get; set;}
     //navigation
      public List<CustomerProperty> CustomerProperties { get; set;}
    }
    
    public class CustomerProperty
    {
      public int CustomerPropertyId { get; set;}
      //navigation
      public Customer Customer { get; set; }
    }
    

    It will pruduce two tables CustomerProperties and Customers, and you can access CustomerProperties from the Customer instance.