我正在尝试使用linq从数据库获取记录,但它保持不返回记录
这是非常基本的sql语句 select * where productid ='12553'
但是以下代码不会返回任何结果。请指教。你呢
private static IEnumerable<ProductModel> GetAllProduct(string productId)
{
using (var dc = new TestEntities())
{
var result = (from a in dc.Products
where a.productid == productId
select new ProductModel
{
ProductId = a.productid,
Name = a.ProductName
});
return result.Distinct().ToList();
}
}
答案 0 :(得分:2)
您不需要在此投影:
using (var dc = new TestEntities())
{
var result = from a in dc.Products
where a.productid == productId
select a;
return result.Distinct().ToList();
}