Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My actual table is like below.

ID name value
1 size 10.5
1 price 100.00
1 color red
4 size 9.5
4 price 150.00
4 color green
6 size 8.5
6 price 200.00
6 color yellow


I am using below code for retrieve the data based on column name(id) but i am getting first row of the entire table like below


1 size 10.5

But i want to get all records of id no 1 like below
1 size 10.5
1 price 100.00
1 color red




my service is like below and just modify my code and help me out

public ProductInfoDvo GetProductInfo(int id)
{
eshop_dbContext dbcontext = new eshop_dbContext();
ProductInfo productInfo = dbcontext.ProductInfoes.FirstOrDefault(p => p.ProductID == id);

return productInfo.ToProductInfoDvo();
}
Posted

1 solution

if you want to get the whole data by id change your code like below
C#
List<productinfo> productInfo = dbcontext.ProductInfoes.Where(p => p.ProductID == id).ToList();

or
C#
var productInfo = dbcontext.ProductInfoes.Where(p => p.ProductID == id).ToList();


Hope this helps
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900