[英]convert rows to column in entity framwork
how can i convert rows to column in entity framework!? 如何在实体框架中将行转换为列!
i have a result like this: 我有这样的结果:
and i want this result: 我想要这个结果:
my entity code i this : 我的实体代码我这样:
(from loanPerson in context.LoanPersons.AsParallel()
join warranter in context.Warranters.AsParallel() on loanPerson.Id equals warranter.LoanPersonId
where loanPerson.Id == 84829
select new
{
loanPersonId = loanPerson.Id,
waranterId = warranter.WarranterPersonID,
}).ToList();
and number of the row always less than 3 and i want to have 3 column. 和行数始终小于3,我想有3列。
please let me know your answer. 请让我知道你的答案。 tanks.
坦克。
This query will return the only one row, where waranterIds
will contain, at this particular case, three WarranterPersonID
values, also this field is of List<int>
type, because it's quantity not known at compile time: 此查询将仅返回一行,在这种情况下,
waranterIds
将包含三个WarranterPersonID
值,该字段也是List<int>
类型的,因为在编译时该数量未知:
var answer = (from loanPerson in context.LoanPersons.Where(x => x.Id == 84829)
join warranter in context.Warranters
on loanPerson.Id equals warranter.LoanPersonId
group warranter by loanPerson.Id into sub
select new
{
loanPersonId = sub.Key,
waranterIds = sub.Select(x => x.LoanPersonId).ToList()
//if you sure, that quantity equals 3,
//you can write this code instead of waranterIds:
//zamen1 = sub.Select(x => x.LoanPersonId).First(),
//zamen2 = sub.Select(x => x.LoanPersonId).Skip(1).First(),
//zamen3 = sub.Select(x => x.LoanPersonId).Skip(2).First()
}).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.