EF4 CTP4 Code First 中带有附加负载列的连接表

发布于 2024-10-05 21:30:23 字数 2580 浏览 0 评论 0原文

我有下表:

WOPartList(定义具有 1 个或多个 Part_Size 的零件) WOPartSize(定义具有 1 个或多个 Part_Size 的大小)

Part_Size(连接表作为 addt 有效负载列,例如 sku、on_hand 等...)

以下是 DAL 的 POCO 类:

    // Real World Scenario:

    // PartList                Related to Part_Size     Related to PartSize  
    //
    // #8 Stainless Lag Bolt   sku- 87234018            size- 2 x 1/2  
    //                         on hand- 214 
    //                         on order- 12 

    // #8 Stainless Lag Bolt   sku- 87234199            size- 3 x 1/2  
    //                         on hand- 81 
    //                         on order- 18 


    // #10 Stainless Lag Bolt  sku- 87237835            size- 1 x 1/2  
    //                         on hand- 11 
    //                         on order- 14 

    // #10 Stainless Lag Bolt  sku- 87237835            size- 2 x 1/2  
    //                         on hand- 11 
    //                         on order- 14 

    // #10 Stainless Lag Bolt  sku- 87237835            size- 3 x 1/2  
    //                         on hand- 11 
    //                         on order- 14 

    // So the idea is to be able to create a size once and use it many times
    // for many different parts... But I need to keep specific statistics for
    // each size of a part...

    // How do I tell the Model that Part_Size is a many-to-many junction table
    // between WOPartSize and WOPartsList as well ?


public class WOPartSize
{

    public int WOPartSizeId { get; set; }
    public DateTime tadded { get; set; }
    public string size { get; set; }

    // Nav Collections
    public virtual ICollection<Part_Size> Parts { get; set; }

}


public class Part_Size   // Junction Table
{
    public int WOPartSizeMMId { get; set; }

    public string part_no { get; set; }
    public string part_descr { get; set; }
    public string sku { get; set; }
    public decimal cost_each { get; set; }
    public decimal price_each { get; set; }
    public int on_hand { get; set; }
    public int on_trucks { get; set; }
    public int on_order { get; set; }

    // Put ICollections<> here ?

}

public class WOPartsList
{

    public int WOPartsListId { get; set; }
    public DateTime tadded { get; set; }
    public string part_descr { get; set; }

    // Nav References
    public virtual WOPartType PartType { get; set; }
    public int WOPartTypeId { get; set; }

    public virtual ICollection<Part_Size> Sizes { get; set; }

}

如何配置连接表?注释?流畅的 API ?我的主要问题是在连接表中获取额外的有效负载字段...否则我会简单地让 EF 为我生成表并且没有 POCO 类...

I have the following tables:

WOPartList (defines parts that have 1 or more Part_Size)
WOPartSize (defines sizes that have 1 or more Part_Size)

Part_Size (junction table as addt payload columns such as sku, on_hand etc...)

Here are the POCO classes for the DAL:

    // Real World Scenario:

    // PartList                Related to Part_Size     Related to PartSize  
    //
    // #8 Stainless Lag Bolt   sku- 87234018            size- 2 x 1/2  
    //                         on hand- 214 
    //                         on order- 12 

    // #8 Stainless Lag Bolt   sku- 87234199            size- 3 x 1/2  
    //                         on hand- 81 
    //                         on order- 18 


    // #10 Stainless Lag Bolt  sku- 87237835            size- 1 x 1/2  
    //                         on hand- 11 
    //                         on order- 14 

    // #10 Stainless Lag Bolt  sku- 87237835            size- 2 x 1/2  
    //                         on hand- 11 
    //                         on order- 14 

    // #10 Stainless Lag Bolt  sku- 87237835            size- 3 x 1/2  
    //                         on hand- 11 
    //                         on order- 14 

    // So the idea is to be able to create a size once and use it many times
    // for many different parts... But I need to keep specific statistics for
    // each size of a part...

    // How do I tell the Model that Part_Size is a many-to-many junction table
    // between WOPartSize and WOPartsList as well ?


public class WOPartSize
{

    public int WOPartSizeId { get; set; }
    public DateTime tadded { get; set; }
    public string size { get; set; }

    // Nav Collections
    public virtual ICollection<Part_Size> Parts { get; set; }

}


public class Part_Size   // Junction Table
{
    public int WOPartSizeMMId { get; set; }

    public string part_no { get; set; }
    public string part_descr { get; set; }
    public string sku { get; set; }
    public decimal cost_each { get; set; }
    public decimal price_each { get; set; }
    public int on_hand { get; set; }
    public int on_trucks { get; set; }
    public int on_order { get; set; }

    // Put ICollections<> here ?

}

public class WOPartsList
{

    public int WOPartsListId { get; set; }
    public DateTime tadded { get; set; }
    public string part_descr { get; set; }

    // Nav References
    public virtual WOPartType PartType { get; set; }
    public int WOPartTypeId { get; set; }

    public virtual ICollection<Part_Size> Sizes { get; set; }

}

How do I configure the junction table ? Annotations ? Fluent API ? My main trouble is getting the additional payload fields in junction table... Otherwise I would simply let EF generate the table for me and have NO POCO class...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文