0

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


        }
4

1 回答 1

2

你不需要在这里投影:

using (var dc = new TestEntities())
{
    var result = from a in dc.Products
                 where a.productid == productId
                 select a;
    return result.Distinct().ToList();
}
于 2013-04-12T06:49:09.687 回答