我是 C# 和 Linq 的新手。
实际上,我想将匿名类型返回到列表中。匿名类型包含 List、String 和 DateTime。我尝试使用下面的代码,但它给出了一个错误。请帮助并告诉我我缺少什么或建议我如何实现这一目标。
//错误:
System.InvalidCastException: Specified cast is not valid..
Run Code Online (Sandbox Code Playgroud)
//编辑C#Linq代码
public List<AuditInfo> GetScanAudit(object Id, DateTime? fromTime, DateTime? toTime, string type = null,
string user = null, Pager pager = null)
{
using (var ctx = new PlantDataContext())
{
var query = from audit in ctx.AuditLog
join ent in ctx.Scans on audit.RecordId equals ent.Id.ToString() into audits
from entaudits in audits.DefaultIfEmpty()
where audit.TypeFullName == "ABCD.DB.Model.Scan"
select new
{
audit,
entaudits
};
if (Id != null) …Run Code Online (Sandbox Code Playgroud)