Selecting a new type from linq query

后端 未结 2 413
醉话见心
醉话见心 2021-01-13 20:43

I\'m trying to transform some data selected out of a repository using Linq.

My code so far:

Repository _repository = new Repository<         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-13 21:05

    Not sure why your first example does not run, it looks Ok, see related question here. Possibly it might be a bug in your db driver ?

    You could try using GroupBy to achieve the same result:

        var disciplines = _repository.Query()     
        .GroupBy(d => new Discipline     
            {         
                 DisciplineCode = d.DisciplineCode,         
                 Name = d.DisciplineName     
            }
        ) 
        .ToList();
    

提交回复
热议问题