我有以下 Linq to Sql:
var subscribers = (from s in dataContext.Employees
where s.RowType == "Edit"
select new SubscriberExportData
{
ID = s.ID.ToString(),
GroupNum = s.GroupNumber,
DivisionNum = s.DivisionNumber,
HireDate = s.HireDate != null ? Convert.ToDateTime(s.HireDate).ToShortDateString() : string.Empty,
EffDate = s.EffectiveDate != null ? Convert.ToDateTime(s.EffectiveDate).ToShortDateString() : string.Empty
}
本质上,如果日期值不为空,则将它们转换为短日期格式。但我收到以下错误:
System.InvalidOperationException 未处理 Message=Could not translate expression 'Table(Employee).Where(s => (s.RowType == "Edit")).Select(s => new SubscriberExportData() { HireDate = IIF((s .HireDate != null), ToDateTime(Convert(s.HireDate)).ToShortDateString(), Invoke(value(System.Func`1[System.String]))), EffDate = IIF((s.EffectiveDate != null ), ToDateTime(Convert(s.EffectiveDate)).ToShortDateString)' 转换为 SQL 并且不能将其视为本地表达式。Source=System.Data.Linq
请让我知道如何解决它。