使用子查询的 linq 查询帮助
任何人都可以帮忙吗?,我被一个 linq 查询困住了。
基本上我有一个返回字段的标准 linq 查询,1 个字段(保险)实际上是另一个 linq 查询,就像这样
// original from this in etc not included to keep msg short>
select new Models.Custom.House.Insurance()
{
Id = v.IdHouse,
Insurances = from gt in GroupHouseTariffs
join i in InsuranceGroup
on new { gt.IdTariff, gt.IdGroup}
equals
new { i.IdTariff, i.IdGroup}
select new
{
InsuranceId = i.Id,
Price = i.Price
}
基本上保险从 Models.Custom 注入到保险属性中。 House,它的工作原理就像我在调试中看到的那样...我在保险中有4条记录..保险在House中是这样定义的,它基本上是另一个小类的Iqueryable..
public IQueryable<Insurance> Insurances { get; set;}
所以我尝试编写一个扩展方法,就像这样
public static IQueryable<House> WithInsuranceId(this IQueryable<House> qry, int insuranceId)
{
return from h in qry
where h.Insurance .. // BUT here is the problem i don't see my properties, I see plenty of linq methods
}
我应该能够看到 InsuranceId 并执行此操作,不是吗?
return from h in qry
where h.Insurance.InsuranceId == 1;
这是这个类(它非常小),
public class Insurance
{
public int? InsuranceId { get; set; }
public float? price{ get; set; }
}
也许我需要了解某种特殊的 lambda :-) ?
非常感谢任何帮助,谢谢。
can anyone help?, i am stuck with a linq query..
basically i have a standard linq query that returns fields, 1 field (insurances) is actually another linq query like so
// original from this in etc not included to keep msg short>
select new Models.Custom.House.Insurance()
{
Id = v.IdHouse,
Insurances = from gt in GroupHouseTariffs
join i in InsuranceGroup
on new { gt.IdTariff, gt.IdGroup}
equals
new { i.IdTariff, i.IdGroup}
select new
{
InsuranceId = i.Id,
Price = i.Price
}
basically insurance is injected into the insurance property from Models.Custom.House, it works as i can see it in my debug ... i have 4 records in the insurance .. insurance is defined like this in House which is basically an Iqueryable of another small class..
public IQueryable<Insurance> Insurances { get; set;}
So i tried to write an extension method, like so
public static IQueryable<House> WithInsuranceId(this IQueryable<House> qry, int insuranceId)
{
return from h in qry
where h.Insurance .. // BUT here is the problem i don't see my properties, I see plenty of linq methods
}
I should be able to see insuranceId and do this , no?
return from h in qry
where h.Insurance.InsuranceId == 1;
Here is the class (its very small)
public class Insurance
{
public int? InsuranceId { get; set; }
public float? price{ get; set; }
}
Maybe there is some sort of special lambda i need to know about :-) ?
Any help really appreciated, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的示例中是否有拼写错误?
我注意到以下内容:
现在,您的实际查询对我来说也是错误的。
House.Insurance 有一个名为 ID 的属性和一个名为 Insurances 的属性,它是一个集合。然而您的查询指出:
您的意思是:
还是:
Are there typos in the sample you posted?
I noticed the following:
Now, your actual query looks wrong to me as well.
House.Insurance has a property called ID and a property called Insurances, which is a collection. Yet your query states:
Do you mean:
Or: