Linq.Dynamic条件在哪里 [英] Linq.Dynamic where condition

查看:129
本文介绍了Linq.Dynamic条件在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我一直在使用System.Linq.Dynamic库.有没有一种方法可以使用具有一对多关系的实体.具体来说,我有3个班级

Hi,
I have been using System.Linq.Dynamic library. Is there a way to use Entities with one to many relationship. To be specific I have 3 classes

class A
{
  public int Id {get;set;}
  ...
  ...
  public Class2 class2 {get;set;}
  public List< Another > Bs{get;set;}
}
class Class2
{
   public int Id{get;set;}
}
class Another
{
   public int Id {get;set;}
}



当一对一的关系时,我可以过滤



I can filter when the relationship is one to one

public IQueryable< T > Select< T >(string condition,object value)
{
 var list=FindAll< T >();//return list of T from database
 var result=list.Where(string.Format("{0} = @0",condition),value);
}
result=Select< A >("class2.Id",1);


上面的调用给我列出了class2的id = 1的A对象的列表.我如何搜索该关系是否为一对多..如何根据每个对象的Bs的第一项(即Bs [0])过滤A对象的列表.是否可以使用Linq.Dynamic.


the above call gives me the list of A objects whose class2''s id=1. how can i search if the relationship is one to many.. how do i filter list of A objects based on each object''s first item of Bs ie Bs[0]. would it be possible to filter using Linq.Dynamic.

推荐答案

进行过滤想要满足条件),然后完全按照您给出的示例进行调用.
毕竟,LINQ引擎盖下有一个for循环.因此,您可以使用的逻辑将是相似的.
You can possibly implement a property in class A that checks the first item of class2 inside it (or however you want the condition to be), then call this exactly as the example you have given.
After all, underneath the hood LINQ does a for loop. So the logic you can use would be similar.


这篇关于Linq.Dynamic条件在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆