Получение данных из нескольких таблиц в веб-API C# и ASP.NET Core [закрыто] ⇐ C#
-
Anonymous
Получение данных из нескольких таблиц в веб-API C# и ASP.NET Core [закрыто]
I want to display data from two tables Purchase bill and Purchase bill details purchase bill is the main table and when we pass purchase bill id want to get purchase bill item details from sub-table.
I have pasted the code what I have tried, but I get this error
System.ArgumentException: An item with the same key has already been added. Key: PurchaseBillID
Code:
PurchaseBillCommon PurchaseBillCommon = new PurchaseBillCommon(); List purchaseBill = new List(); List purchaseBillDetails = new List(); Caf_PurchaseBill product = null; try { purchaseBill = _dbContext.Caf_PurchaseBill.FromSqlRaw("SP_Cafeteria_GetPurchaseBill").ToList(); if (purchaseBill != null && purchaseBill.Count > 0) { SqlParameter[] sqlParameters = new SqlParameter[1]; sqlParameters[0] = new SqlParameter("@PurchaseBillID", System.Data.SqlDbType.Int); sqlParameters[0].Value =4; purchaseBillDetails = _dbContext.Caf_PurchaseBillDetails.FromSqlRaw("SP_Cafeteria_GetPurchaseBillDetails @PurchaseBillID", sqlParameters).ToList(); PurchaseBillCommon.PurchaseBillDetails = purchaseBillDetails; PurchaseBillCommon.StatusCode = 200; PurchaseBillCommon.Message = "Record fetching sucessfully..."; PurchaseBillCommon.Status = "Sucess"; } else { PurchaseBillCommon.PurchaseBillDetails = null; PurchaseBillCommon.StatusCode = 500; PurchaseBillCommon.Message = "No Records found...?"; PurchaseBillCommon.Status = "Fail"; } } catch (Exception ex) { PurchaseBillCommon.PurchaseBillDetails = null; PurchaseBillCommon.StatusCode = 500; PurchaseBillCommon.Message = "No Records found...?" + ex.Message; PurchaseBillCommon.Status = "Fail"; } return PurchaseBillCommon;
Источник: https://stackoverflow.com/questions/780 ... re-web-api
I want to display data from two tables Purchase bill and Purchase bill details purchase bill is the main table and when we pass purchase bill id want to get purchase bill item details from sub-table.
I have pasted the code what I have tried, but I get this error
System.ArgumentException: An item with the same key has already been added. Key: PurchaseBillID
Code:
PurchaseBillCommon PurchaseBillCommon = new PurchaseBillCommon(); List purchaseBill = new List(); List purchaseBillDetails = new List(); Caf_PurchaseBill product = null; try { purchaseBill = _dbContext.Caf_PurchaseBill.FromSqlRaw("SP_Cafeteria_GetPurchaseBill").ToList(); if (purchaseBill != null && purchaseBill.Count > 0) { SqlParameter[] sqlParameters = new SqlParameter[1]; sqlParameters[0] = new SqlParameter("@PurchaseBillID", System.Data.SqlDbType.Int); sqlParameters[0].Value =4; purchaseBillDetails = _dbContext.Caf_PurchaseBillDetails.FromSqlRaw("SP_Cafeteria_GetPurchaseBillDetails @PurchaseBillID", sqlParameters).ToList(); PurchaseBillCommon.PurchaseBillDetails = purchaseBillDetails; PurchaseBillCommon.StatusCode = 200; PurchaseBillCommon.Message = "Record fetching sucessfully..."; PurchaseBillCommon.Status = "Sucess"; } else { PurchaseBillCommon.PurchaseBillDetails = null; PurchaseBillCommon.StatusCode = 500; PurchaseBillCommon.Message = "No Records found...?"; PurchaseBillCommon.Status = "Fail"; } } catch (Exception ex) { PurchaseBillCommon.PurchaseBillDetails = null; PurchaseBillCommon.StatusCode = 500; PurchaseBillCommon.Message = "No Records found...?" + ex.Message; PurchaseBillCommon.Status = "Fail"; } return PurchaseBillCommon;
Источник: https://stackoverflow.com/questions/780 ... re-web-api
Мобильная версия