通过加入从另一个列表中填写属性
我有两个模型:
public class Payment
{
public Guid UserId {get;set;}
public string UserName {get;set;}
public string AddressLine1 {get;set;}
public string AddressLine2 {get;set;}
public decimal Amount{get;set;}
}
public class User
{
public Guid Id {get;set;}
public string Name {get;set;}
public string PhoneNumber {get;set;}
}
在业务逻辑中,我正在做一些事情并接收两个对象:
list< user>用户
和list<付款>付款
。属性用户名
付款的一件事是空的,我需要通过加入两个列表(user.id == payment.userid)来填充它,
。
如何加入两个列表并接收列表<付款>付款
带有填充<代码>用户名?
I have two models:
public class Payment
{
public Guid UserId {get;set;}
public string UserName {get;set;}
public string AddressLine1 {get;set;}
public string AddressLine2 {get;set;}
public decimal Amount{get;set;}
}
public class User
{
public Guid Id {get;set;}
public string Name {get;set;}
public string PhoneNumber {get;set;}
}
In business logic I am doing some stuff and receive two objects:
List<User> users
and List<Payment> payments
. One thing that properties UserName
in payments
are empty and I need to fill it by joining two lists (user.Id==payment.UserId)
.
How to join two lists and receive List<Payment> payments
with a filled UserName
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有很多方法可以使用:
解决方案1:
付款
JOIN 用户。或
解决方案2:迭代
付款
和查询用户
。There are plenty of ways to work with:
Solution 1:
payments
joinusers
.Or
Solution 2: Iterate with
payments
and query foruser
.使用以下方式:
use this :