Querying Entity with LINQ using Dyanmic Field Name

前端 未结 3 680
庸人自扰
庸人自扰 2020-12-15 15:08

I have created a dynamic search screen in ASP.NET MVC. I retrieved the field names from the entity through reflection so that I could allow the user to choose which fields

3条回答
  •  旧时难觅i
    2020-12-15 15:19

    Have you tried getting the value from PropertyInfo?

    entities.People.Where(p => (p.GetType().GetProperty(key).GetValue(p, null) as string) == fieldValueDictionary[key])
    

提交回复
热议问题