使用 LINQ 将 2 个表合并为 1 个类
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不想使用 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) ?
我不确定这是否适用于您所需的解决方案,但是您是否考虑过简单的 CustomerPaymentViewModel 类?
I'm not sure if this applies to your needed solution, but have you considered a simple CustomerPaymentViewModel class?