【发布时间】:2012-09-13 03:15:48
【问题描述】:
我有以下 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=无法翻译表达式'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
请告诉我如何解决它。
【问题讨论】:
-
您使用的是哪种语言,VB 还是 C#?
标签: linq