![](/img/trans.png)
[英]linq to sql with stored procedure how to change display(UI) column name
[英]how to display name use LINQ
实际上我有两个表我想显示第二个表的使用记录。 请帮助我。 让我给你举个例子。
[TABLE1]
LocationID LoginID Location_Name
1 101 A
2 102 B
3 103 C
[TABLE2]
ID LoginID No_Of_Item Location ToLocation
1 101 5 1 2
2 102 6 2 3
3 103 7 1 3
这是我的数据库。 现在我想显示带有位置名称的 [TABLE2] 记录。 但我无法做到这一点。 请在此 LINQ 查询中帮助我。
这是我的代码。
public IQueryable<StockTransferViewModel> GetAllStockTransferDetailByLoginId(string LoginId)
{
var StockList = (from aspuser in context.AspNetUsers
join cus in context.Customers on aspuser.Id equals cus.LoginID
join transfer in context.StockTransfers on aspuser.Id equals transfer.LoginID
where transfer.LoginID == LoginId
select new StockTransferViewModel
{
ID = transfer.ID,
LoginID = transfer.LoginID,
Date_Of_Transfer = transfer.Date_Of_Transfer,
No_Of_Sku = transfer.No_Of_SKU,
FromLocationName=transfer.Location,
ToLocation=transfer.ToLocation,
}).AsQueryable();
return StockList;
}
如果TABLE1
被命名为Locations
,您可能希望在以join transfer in
开头的行之后添加以下行:
join fromLocation in context.Locations on transfer.Location equals fromLocation.LocationID
join toLocation in context.Locations on transfer.Location equals toLocation.LocationID
然后在您的选择语句中,您需要:
FromLocationName = fromLocation.Location_Name,
ToLocation = toLocation.Location_Name,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.