无法将类型“匿名类型”强制转换为“Transcriber.Models.Jobs”。 LINQ to Entities仅支持转换EDM原语或枚举类型

时间:2015-04-10 06:40:54

标签: c# linq

当我调用fetchGroups方法时,我在

中收到错误
var result = gp.Cast<Jobs>().ToList();

我对linq很新。有任何建议请。

型号:

public List<Jobs> fetchGroups(decimal Trans_ID, decimal Job_Id)
{
    var gp = (from Trans_Mast in r2ge.Transcription_Tracker
                      where Trans_Mast.Transcription_Id == Trans_ID && 
                            Trans_Mast.Entity_Id == Job_Id
                      select
                          new
                          {
                              Trans_Mast.Group_Name
                          }).Distinct();
    var result = gp.Cast<Jobs>().ToList();
    return result;
}

public class Job
{
    List<Room> room = new List<Room>();
    public int totalImage { get; set; }
    public int totalAudio { get; set; }
    public int Transcribe_Rooms { get; set; }
    public DateTime DataTime { get; set; }
    public DateTime CreatedOn { get; set; }
    public DateTime LastModified { get; set; }
}

1 个答案:

答案 0 :(得分:1)

问题的答案是

    List<string> gp = (from Trans_Mast in r2ge.Transcription_Tracker
                       where Trans_Mast.Transcription_Id == Trans_ID && Trans_Mast.Entity_Id == Job_Id && Trans_Mast.Group_Name != null
                       select new
                       {
                           Trans_Mast.Group_Name
                       }).AsEnumerable().Select(dr => dr.Group_Name).Distinct().ToList();