我尝试获取myClass的新列表,其属性等于虚拟类属性集。我不知道我如何写一个linq表达式可以做到这一点。 特别是这个列表来自EntityFramework,所以如果没有必要,我不想一次拉出所有的数据。在类属性值列表中搜索,其中等于属性集值
像:
public class MyClass
{
public int MyInt { get; set; }
public string MyString { get; set; }
public bool MyBool { get; set; }
public DateTime MyDate { get; set; }
}
public List<MyClass> myClassList = new List<MyClass>();
/// <summary>
///
/// </summary>
/// <param name="myClass">A Dummy Class where stored the searched values</param>
/// <param name="searchingPropertiesName">a string array where stored the searched property names</param>
public void MySearch(MyClass myClass, string[] searchingPropertiesName)
{
var propInfo = new List<System.Reflection.PropertyInfo>();
foreach (System.Reflection.PropertyInfo myClassProp in typeof(MyClass).GetProperties(System.Reflection.BindingFlags.Public))
{
foreach (string searchPropName in searchingPropertiesName)
{
if (myClassProp.Name != searchPropName)
{
return;
}
propInfo.Add(typeof(EventSeries).GetProperty(searchPropName));
}
}
var searchedList = myClassList.Where(e => e... "e.Property values are equal propInfo.values");
}
谢谢!
你想比较一个特定的属性,或所有的? –