开发者

Combine 2 tables in 1 class using LINQ

I have 2 classes:

[Table(Name = "_Reference2")]
public class Customer
{
    [Column(Name = "_IDRRef")]
    public Binary CustomerRef { get; set; }
    [Column(Name = "_Description")]
    public string Name { get; set; }
}

[Table(Name = "_AccumReg2210")]
public class Payment
{
    [Column(Name="_Period")]
    public DateTime Period开发者_如何学JAVA { get; set; }
    [Column(Name = "_Fld2211RRef")]
    public Binary Customer { get; set; }
    [Column(Name = "_Fld5051RRef")]
    public decimal Sum { get; set; }
}

Is there any opportunity to combine this classes in 1 class? Usually, I need to write query witn JOIN (ON Customer.CustomerRef = Payment.Customer) to this classes. It will be better to implement complex class, connected to both tables.


var results = from c in Customers
              from p in Payments
              where p.Customer == c.CustomerRef
              select new ComplexObject() {
                 Name = c.Name,
                 ...
              };


If you don't want to join explicitly the two tables using Linq, you could create a View in your database and generate a model with it (using LinqToSQL or Entities Framework) ?


I'm not sure if this applies to your needed solution, but have you considered a simple CustomerPaymentViewModel class?

public class CustomerPaymentViewModel
{
    public Customer { get; set; }
    public Payment { get; set; }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜