mvc4与实体框架 [英] mvc4 with entity framework
问题描述
我的实际表格如下。
ID 名称 值
1尺寸10.5
1价格100.00
1颜色红色
4尺寸9.5
4价格150.00
4颜色绿色
6尺寸8.5
6价格200.00
6颜色黄色< br $> b $ b
我使用下面的代码来检索基于列名(id)的数据但是我得到的第一行整个桌子如下
1尺寸10.5
但我希望得到ID为1的所有记录,如下所示
1尺寸10.5
1价格100.00
1红色
我的服务如下,只需修改我的代码并帮助我
public ProductInfoDvo GetProductInfo(int id)
{
eshop_dbContext dbcontext = new eshop_dbContext();
ProductInfo productInfo = dbcontext.ProductInfoes.FirstOrDefault(p => p.ProductID == id);
return productInfo.ToProductInfoDvo();
}
如果你想通过id获取整个数据,请改变你的代码,如下所示
List< productinfo> productInfo = dbcontext.ProductInfoes.Where(p = > p.ProductID == id)。ToList();
或
var productInfo = dbcontext.ProductInfoes.Where(p = > p.ProductID == id)。ToList();
希望这有帮助
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();
}
if you want to get the whole data by id change your code like below
List<productinfo> productInfo = dbcontext.ProductInfoes.Where(p => p.ProductID == id).ToList();
or
var productInfo = dbcontext.ProductInfoes.Where(p => p.ProductID == id).ToList();
Hope this helps
这篇关于mvc4与实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!