相关疑难解决方法(0)

获取对象内的所有关联/复合对象(以抽象方式)

业务:

我有一个支付系统,可以通过GiftCoupon,ClubMembershipCard等支付.一个支付本身可以有多个支付组件

课程:

我有一个付款类.它有支付组件,如GiftCouponPayment,ClubMembershipCardPayment,CashPayment等.每种组件类型都满足通用接口IPaymentComponent.我使用有关现有类型的知识实现了它.

问题

1)如何以抽象的方式实现这个功能- 不知道存在哪些类型?这意味着它需要适用于实现IPaymentComponent接口的所有类型.

2)如果在LINQ to SQL中无法实现它,是否可以在Entity Framework中实现?

3)当LINQ to SQL在Payment对象中生成GiftCouponPayment实体时,它是关联/聚合还是组合?

注意:我使用LINQ to SQL作为ORM.GiftCouponPayment和Payment是自动生成的类,这些对象由ORM创建.我通过使用部分类为这些类添加了更多功能.

注意:在数据库中,每个PaymentComponent(例如GiftCouponPayment)都有自己的属性(例如CouponValue,CardValue等).因此,按层次结构表将不会很好.我们需要单独的表格.那条线路有解决方案吗?

注意:此付款之前,数据库中已存在GiftCouponPayment.我们需要使用客户提供的GiftCouponPaymentID来识别GiftCouponPayment对象.我们只需要更新此表中的PaymentID列.

泄漏抽象是指任何已实现的抽象,旨在减少(或隐藏)复杂性,其中底层细节未被完全隐藏

LINQ to SQL Diagram

在此输入图像描述

参考:

  1. 实体框架4,继承vs扩展?
  2. 如何选择继承策略http://blogs.msdn.com/b/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx
  3. 流畅的API示例 - http://blogs.msdn.com/b/adonet/archive/2010/12/14/ef-feature-ctp5-fluent-api-samples.aspx

C#代码

public interface IPaymentComponent
{
     int MyID { get; set; }
     int MyValue { get; set; }
     int GetEffectiveValue();
}


public partial class GiftCouponPayment : IPaymentComponent
{
    public int MyID
    {
        get 
        { 
            return this.GiftCouponPaymentID; 
        }
        set 
        { 
            this.GiftCouponPaymentID = …
Run Code Online (Sandbox Code Playgroud)

c# oop domain-driven-design entity-framework linq-to-sql

6
推荐指数
1
解决办法
1216
查看次数