我有两个实体:
public class Transport
{
[Key]
public int TransportID {get; set;}
public string Model { get; set; }
public string Brand { get; set; }
}
public class TransportOwner
{
[Key]
public int TransportOwnerID {get; set;}
public int OwnerID {get; set;}
public int TransportID {get; set;}
[ForeignKey("TransportID")]
public virtual Transport Transport { get; set; }
}
在 ViewModel 中,我从这两个实体创建了两个列表:
public List<Transport> TransportList
public List<OwnerTransport> OwnerTransportList
我需要使用这两个列表中的数据为我的 WPF/MVVM 表单构建第三个列表: 我需要的结构是:
OwnerTransportID
OwnerID
TransportID
Model
Brand
我接下来在 ViewModel.cs 中做什么?我需要创建新课程吗?
public class OwnerTransportTransport
{
[Key]
public int OwnerTransportID {get; set;}
public int TransportID {get; set;}
public string OwnerID {get; set;}
public string Model { get; set; }
public string Brand { get; set; }
}
接着
List<OwnerTransport> OwnerTransportTransportList
?? 你能帮忙吗?
我从 linq 查询中获得的数据:
var ownerTransportList = OwnerTransport.Select(t => new
{
t.OwnerTransportID,
t.OwnerID,
t.TransportID,
ModelName = t.Transport.ModelName,
BrandName = t.Transport.BrandName,
}).ToList();
所以我有数据,不知道如何将其转换为List<OwnerTransportTranspot>
.