【发布时间】:2020-02-11 09:57:41
【问题描述】:
我需要从名为Student 的实体中获取数据,该实体具有字段(Id、Name、Age、Dob)。我有一个请求对象StudentFilter
public class StudentFilter
{
public int? Id {get;set;}
public string Name {get;set;}
public int Age {get;set;}
public DateTime Dob {get;set;}
}
现在基于此,我需要使用这些过滤器形成一个查询并从数据库中获取数据:
public List<Student> Get(StudentFilter request)
{
if(request.Id.HasValue && request.Id > 0)
{
}
if(request.Age.HasValue && request.Age > 0)
{
}
if(request.Dob.HasValue)
{
}
_context.<Student>.Get()
}
有人可以帮我吗?在此先感谢
【问题讨论】:
-
到目前为止您尝试过什么?您是否遇到了具体问题?
-
添加了答案
标签: c# entity-framework entity-framework-core linq-to-entities