我对实体框架有疑问。 当我构建一个动态lambda表达式如下:
Expression<Func<Product, bool>> where = x => (Constant.STR_BLANK.Equals(imei) || x.Imei.Contains(imei) ) &&
(Constant.STR_BLANK.Equals(productName) || x.ProductName.Equals(productName)) &&
(categoryID == -1 || x.CategoryID == categoryID) &&
(Constant.STR_BLANK.Equals(shopName) || x.ShopName.Equals(shopName)) &&
(x.DateImport >= start && x.DateImport <= end);
当我为imei或productName或任何字符串参数传递值时,我收到错误:
InnerException: System.InvalidOperationException
HResult=-2146233079
Message=p__linq__0 : String truncation: max=0, len=1, value='3'.
Source=System.Data.SqlServerCe
实体:
public class Product
{
[DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
public int ProductID { get; set; }
[StringLength(200)]
public string ProductName { get; set; }
//[ForeignKey("CategoryID")]
public int CategoryID { get; set; }
[MaxLength(200)]
public string ShopName { get; set; }
public int CountWarranty { get; set; }
public decimal Price { get; set; }
[MaxLength(100)]
public string Imei { get; set; }
public DateTime DateImport { get; set; }
public int Status { get; set; }
public virtual Category Category { get; set; }
}
我发现很多线程都有同样的问题,但我无法修复此错误。任何人都可以帮助我。抱歉我的英语不好。感谢。