如何在 Linq to Entities 中使用 List<string> 作为实体?

How can I use List<string> in Linq to Entities as Entities?

我有一个类型为 StringList,其中它的值与我的实体 class、

中的属性同名

例如, 我有 List<string>

List<String> list = new List<String>(new String[]{ "Name", "Age", "Value" });

现在我必须使用 LinqtoEntities 使用列表中的值查询我的 table 像这样:

db.Mytable.Where(z=>z.MyListValue1==SomeValue && z.MylistValue2==SomeValue &&
                    z.MyListValue3==SomeValue) 

这可能吗?或者还有其他解决方法吗? 因为我的 List<string> 值与我的 Class 属性相同

我在 EF5、Mvc5 和 Oracle11g 中使用 DB FIRST 方法

您可以使用 Contains:

db.Mytable.Where(z => list.Contains(z.YourPoperty))

该列表包含您要比较的属性名称?以前从来没有这样做过,所以没有例子,但我会这样做:

动态 linq 是实现它的一种方法 https://dynamiclinq.codeplex.com/

另一个在反思自己

最后一个是尝试使用 db.Entry() 然后 Property() 方法 https://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.dbentityentry.property(v=vs.113).aspx#M:System.Data.Entity.Infrastructure.DbEntityEntry.Property(System.String)