[英]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.