0

我正在尝试List of Object在 LINQ 语句中加载。但我不知道该怎么办?请看下面的代码并理解

public class TechDisciplines
     {
            public string CustomerNumber { get; set; }            
            public string Status { get; set; }           
            public string Error { get; set; }    
            public IList<TechnicalDisciplines> TechnicalDisciplines { get; set; }
     }

     public class TechnicalDisciplines
     {
        public string Code { get; set; }
        public string Name { get; set; }     
        public string Cardinality { get; set; }   
        public string SubdisciplineName { get; set; }    
        public string SubdisciplineCode { get; set; }

    }

LINQ

var results = from uctd in _context.USR_CUS_TECH_DISC
                   join ac in _context.APP_CODE on new {TECH_DISC = uctd.TECH_DISC }
                            equals new {TECH_DISC = ac.CODE} into APP_CODE_join
                   from ac in APP_CODE_join.DefaultIfEmpty()
                   join asc in _context.APP_SUBCODE on
                         new { TECH_SUB_DISC = uctd.TECH_SUB_DISC } equals
                         new {TECH_SUB_DISC = asc.SUBCODE} into APP_SUBCODE_join
                   from asc in APP_SUBCODE_join.DefaultIfEmpty()
                   where ac.SUBSYSTEM == "CUS" && (ac.TYPE == "TECH_DISC" || ac.TYPE == null) 
                   && (asc.TYPE == "TECH_DISC" || asc.TYPE == null) 
                   && uctd.MASTER_CUSTOMER_ID == CustomerNumber
                   select new TechDisciplines()
                          {
                             CustomerNumber = uctd.MASTER_CUSTOMER_ID,

                             //How to load List<TechnicalDisciplines> in list here????
                             TechnicalDisciplines = new TechnicalDisciplines()
                             {
                                 Code = uctd.TECH_DISC,
                                 Name = ac.DESCR,
                                 Cardinality = uctd.PRIMARY_FLAG,
                                 SubdisciplineCode = uctd.TECH_SUB_DISC,
                                 SubdisciplineName = asc.DESCR
                              },
                              Status = "OK"

                           };

如何List<TechnicalDisciplines>进入 LINQ 语句?

4

1 回答 1

1

From what I can see, it appears you should be making a single TechDisciplines instance, filled with TechnicalDisciplines based on your query results.

If I understand your requirements correctly, you need to do:

var tds = from uctd in _context.USR_CUS_TECH_DISC
               join ac in _context.APP_CODE on new {TECH_DISC = uctd.TECH_DISC }
                        equals new {TECH_DISC = ac.CODE} into APP_CODE_join
               from ac in APP_CODE_join.DefaultIfEmpty()
               join asc in _context.APP_SUBCODE on
                     new { TECH_SUB_DISC = uctd.TECH_SUB_DISC } equals
                     new {TECH_SUB_DISC = asc.SUBCODE} into APP_SUBCODE_join
               from asc in APP_SUBCODE_join.DefaultIfEmpty()
               where ac.SUBSYSTEM == "CUS" && (ac.TYPE == "TECH_DISC" || ac.TYPE == null) 
               && (asc.TYPE == "TECH_DISC" || asc.TYPE == null) 
               && uctd.MASTER_CUSTOMER_ID == CustomerNumber
               select new TechnicalDisciplines()
                         {
                             Code = uctd.TECH_DISC,
                             Name = ac.DESCR,
                             Cardinality = uctd.PRIMARY_FLAG,
                             SubdisciplineCode = uctd.TECH_SUB_DISC,
                             SubdisciplineName = asc.DESCR
                         };

var result = new TechDisciplines
             {
                  CustomerNumber = CustomerNumber,
                  TechnicalDisciplines = tds.ToList()
             };
于 2013-10-01T21:22:00.773 回答