使用 LINQ 将 2 个表合并为 1 个类

发布于 2024-11-19 23:40:22 字数 649 浏览 3 评论 0原文

我有 2 个课程:

[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 { get; set; }
    [Column(Name = "_Fld2211RRef")]
    public Binary Customer { get; set; }
    [Column(Name = "_Fld5051RRef")]
    public decimal Sum { get; set; }
}

是否有机会将这些课程合并为 1 个课程?通常,我需要向此类编写查询 JOIN (ON Customer.CustomerRef = Payment.Customer)。最好实现连接到两个表的复杂类。

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 { 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.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

再见回来 2024-11-26 23:40:23

如果您不想使用 Linq 显式连接两个表,您可以在数据库中创建一个视图并用它生成一个模型(使用 LinqToSQL 或实体框架)?

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) ?

逐鹿 2024-11-26 23:40:23

我不确定这是否适用于您所需的解决方案,但是您是否考虑过简单的 CustomerPaymentViewModel 类?

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

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; }
}
浅笑轻吟梦一曲 2024-11-26 23:40:22
var results = from c in Customers
              from p in Payments
              where p.Customer == c.CustomerRef
              select new ComplexObject() {
                 Name = c.Name,
                 ...
              };
var results = from c in Customers
              from p in Payments
              where p.Customer == c.CustomerRef
              select new ComplexObject() {
                 Name = c.Name,
                 ...
              };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文