在我的數據庫日期字段保存在爲nvarchar(10)。在這裏我想compaire兩個日期一起 這是我的代碼:中的EntityFramework查詢轉換字符串類型爲DateTime
public bool SalesFactorIsExist(IFeeKindDTO inFeeKindDTO)
{
bool isExist = false;
int count = 0;
var context = new SabzNegar01Entities1();
try
{
count = (from p in context.tbl_SalesFactor_D
where p.tbl_SalesFactor_M.tbl_Customer.CustomerGroupCode == inFeeKindDTO.CustomerGroupCode && p.StockCode == inFeeKindDTO.StockCode && ConvertStringDate(p.tbl_SalesFactor_M.FactorSalesDate) >= ConvertStringDate(inFeeKindDTO.StartDate)
select new { p.Row }).Count();
if (count != 0)
{
isExist = true;
}
}
catch (Exception ex)
{
PMessageBox.Show("خطا در خواندن اطلاعات", "اخطار", PMessageBoxButtons.Ok, PMessageBoxIcons.Error);
}
return isExist;
}
我從這個方法使用:
private DateTime ConvertStringDate(string inDate)
{
DateTime result = DateTime.Parse(inDate);
return result;
}
但有一個錯誤:
LINQ to Entities does not recognize the method 'System.DateTime ConvertStringDate(System.String)' method, and this method cannot be translated into a store expression.
我該怎麼辦? 還有別的辦法嗎?
什麼是錯誤文本? – Maess