不能隐式转换类型  syste.collections.generics.list'到' system.collections.generics.list'

时间:2015-05-02 11:12:25

标签: c# asp.net asp.net-mvc entity-framework

我收到错误:

  

无法隐式将System.Collections.Generics.List<MeritMaste_QuestionPeparsettings>类型转换为System.Collections.Generics.List<MeritMaste.data.MeritMAster_QuestionPeparSettng>

  1. 是数据库连接问题吗?
  2. 是数据库连接错误吗?
  3. public class DataManager
    {
        public static void OnlineExamLists(
            out List<MeritMaste_QuestionPaperSettings> examQuestionSettings,
            out List<MeritMaster_QuestionBank> questionBanks, string examCode)
        {
    
            using (var dbcontext = new meritmasterEntities())
            {
    
                // var exam_code = dbcontext.MeritMaste_QuestionPaperSettings.Where(m => m.ID == examCode).FirstOrDefault().ex_code;
                //(from k in dbcontext.MeritMaste_QuestionPaperSettings where k.Status == true && k.ID == examCode select k.ex_code).ToList();
    
                examQuestionSettings = (from k in dbcontext.MeritMaste_QuestionPaperSettings 
                                        where k.Status == true && k.ex_code == examCode 
                                        select k).ToList();
    
                var examsettingslocal = examQuestionSettings.FirstOrDefault();
    
                var kabqu = new List<MeritMaster_QuestionBank>();
                var queBank = examsettingslocal == null
                    ? kabqu
                    : (from k in dbcontext.MeritMaster_QuestionBank
                        where k.Status == true && k.Course_ID == examsettingslocal.CourseId
                        select k).ToList();
                // questionBanks = queBank.ToList();
    
                var questionbanklocal = dbcontext.MeritMaste_QuestionPaperSettings.ToList();
    
    
                questionBanks = (from es in examQuestionSettings.ToList()
                                    join qb in queBank.ToList() on new {p1 = (int) es.CourseId, p2 = (int) es.QuestionIds} equals
                                        new {p1 = (int) qb.Course_ID, p2 = (int) qb.ID}
    
                                    where es.ex_code == examCode && es.Status == true && qb.Status == true
                                    select qb).ToList();
                //join a in questionpaperlocal.ToList() on k.QuestionIds equals a.ID
                //where k.Status == true && a.Status == true
                ////orderby a.Id ascending
                //select k
            }
        }
    }
    

1 个答案:

答案 0 :(得分:0)

MeritMaste_QuestionPeparsettingsMeritMaste.data.MeritMAster_QuestionPeparSettng是编译器的两种不同类型,并且在这两种类型之间不存在转换。

您需要定义转换(隐式或显式),或手动转换它们。您可以使用各种技术执行此操作,例如使用IQueryable.ForAllIEnumerable.Select扩展方法。