【问题标题】:EF4 POCO Many To OneEF4 POCO 多对一
【发布时间】:2011-02-01 18:51:18
【问题描述】:

我正在尝试让一个 POCO 对象包含 2 个表。

我有 2 张桌子:

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

我会有一个 POCO 对象:
Customer

- CustomerId
- Name
- CustomerProperties
- ExtendedProperties

你有什么想法吗?

【问题讨论】:

    标签: c# .net entity-framework-4 poco


    【解决方案1】:

    这是代码优先的解决方案(没有流畅的代码)。

    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; }
    }
    

    它会生成两张表 CustomerProperties 和 Customers,您可以从 Customer 实例访问 CustomerProperties。

    【讨论】:

    • @我从你的回答中学到了一些东西。如何从我的客户实例中显示 CustomerProperty 的属性?我只能显示 CustomerProperty 实例中的 Customer 属性?
    猜你喜欢
    • 1970-01-01
    • 2011-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    相关资源
    最近更新 更多