문제

0I want to perform the linq select query for getting the anonymous type field which is a concatenation of two fields.

(from c in ctx.Documents
where c.FileName == doc.FileName
select new
{
    fileName = c.FileName + "" + c.UploadDate,
    value = c.UploadDate
}).ToList();

but this linq query throws the exception

Unable to cast the type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.

please guide me to solve this error. I know that it is because of the concatenation of date with string but how do i resolve the isse and get the desired output.

Thanks, Please reply fast.

도움이 되었습니까?

해결책

try like this:

(from a in
(from c in ctx.Documents 
     where c.FileName == doc.FileName
     select c).AsEnumerable() 
     select new { fileName = a.FileName + "" + a.UploadDate, 
                  value = a.UploadDate }).ToList();

다른 팁

try this

  fileName = c.FileName == null ? String.Empty : c.FileName + c.UploadDate== null ? :   String.Empty : c.UploadDate ;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top