如何:linq查询

时间:2013-04-12 06:45:52

标签: linq

我正在尝试使用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();
            }


        }

1 个答案:

答案 0 :(得分:2)

您不需要在此投影:

using (var dc = new TestEntities())
{
    var result = from a in dc.Products
                 where a.productid == productId
                 select a;
    return result.Distinct().ToList();
}