可能的重复:
无法在 LINQ to Entities 查询中构造实体
var tasks = from i in data.Incidents
join a in data.Accounts on i.CustomerID equals a.Acct_CID
select new Tasks()
{
creator_id = a.ID,
start_date = i.DateOpened,
end_date = i.DateCLosed,
product_code = i.ProductCode,
install_type = i.InstallType,
os = i.OSType,
details = i.Description,
solution = i.Solution,
creator_name = i.TechID,
category = i.Title,
text = "Ticket for" + " " + i.Name,
status_id = 7
};
foreach (var task in tasks)
data.Tasks.Add(task);
data.SaveChanges();
public class Incidents
{
[Key]
public int IncidentID { get; set; }
public string CustomerID { get; set; }
public string ProductCode { get; set; }
public string TechID { get; set; }
public DateTime DateOpened { get; set; }
public DateTime DateCLosed { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Solution { get; set; }
public string Name { get; set; }
public string OSType{ get; set; }
public string InstallType { get; set; }
public string AddOnSoftware { get; set; }
public string ScreenShare { get; set; }
}
当我尝试迭代时出现错误,我希望得到一些帮助
在 Linq-to-Entities 中,您只能投影到匿名类型或常规类。您无法投影到现有实体类型。你可以像这样使用 linq-to-objects
var tasks = (from i in data.Incidents
join a in data.Accounts on i.CustomerID equals a.Acct_CID
select new
{
creator_id = a.ID,
start_date = i.DateOpened,
end_date = i.DateCLosed
// ...
}).AsEnumerable().Select(x => new Tasks {
creator_id = x.creator_id,
start_date = x.start_date,
end_date = x.end_date
}).ToList();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)