Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 表达式<;Func<;T1、T2、TResult>&燃气轮机;中的Sql和Sql_C#_Entity Framework - Fatal编程技术网

C# 表达式<;Func<;T1、T2、TResult>&燃气轮机;中的Sql和Sql

C# 表达式<;Func<;T1、T2、TResult>&燃气轮机;中的Sql和Sql,c#,entity-framework,C#,Entity Framework,我想使用表达式树来制作带有实体框架的过滤器 这就是我喜欢的类型 public class Type1 { public string Name { get; set; } } public class Type2 { public IEnumerable<string> Names { get; set; } } 公共类类型1 { 公共字符串名称{get;set;} } 公共类类型2 { 公共IEnumerable名称{get;set;} } 这是我的说明书 p

我想使用表达式树来制作带有实体框架的过滤器

这就是我喜欢的类型

public class Type1
{
    public string Name { get; set; }
}

public class Type2
{
    public IEnumerable<string> Names { get; set; }
}
公共类类型1
{
公共字符串名称{get;set;}
}
公共类类型2
{
公共IEnumerable名称{get;set;}
}
这是我的说明书

public Expression<Func<Entities.Type1, bool>> MyExpression(Type2 filter)
{
    //something like where name in (name[0], name[1], ... name[n])
}
公共表达式MyExpression(类型2筛选器) { //类似于where name in(名称[0]、名称[1]、…名称[n]) } 我需要将其转换为类似于Sql where in的内容

我该怎么做,最好的形式是什么


如何让实体框架以我想要的方式理解我的任意表达式?

您可以这样做:

public Expression<Func<Type1, bool>> MyExpression(Type2 filter)
{
    return x => filter.Names.Contains(x.Name);
}
公共表达式MyExpression(类型2筛选器) { 返回x=>filter.Names.Contains(x.Name); } 您可以尝试以下方法:

public Expression<Func<Type1, bool>> MyExpression(Type2 filter)
{
    Expression<Func<Type1, bool>> expression =  t1 => filter.Names.Contains(t1.Name);
    return expression;
}
公共表达式MyExpression(类型2筛选器) { Expression=t1=>filter.Names.Contains(t1.Name); 返回表达式; }
在这里,您可以找到很好的解释,为什么可以将lambda表达式转换为表达式树。

问题是?是“我如何让实体框架以我想要的方式解释我的任意表达式?”是的,让我用你的问题更好地解释我的问题=
type1s.Where(t1=>filter.Names.Contains(t1.Name))