我嘗試獲取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");
}
謝謝!
你想比較一個特定的屬性,或所有的? –