简体   繁体   中英

how to display name use LINQ

Actually i have two tables i want to display records of the use of second table. Please help me in this. Let me provide you example.

[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

This is my database. Now i want to show [TABLE2] records with location name. But i am unable to do that. Please help me in this LINQ Query.

This is my code.

 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;
    }

If TABLE1 is named Locations , you'll likey want to add the following lines after the line starting with 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

Then in your select statement, you'll want:

FromLocationName = fromLocation.Location_Name,
ToLocation = toLocation.Location_Name,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM