Model view controller Telerik Openaccess ORM扩展域模型

Model view controller Telerik Openaccess ORM扩展域模型,model-view-controller,telerik,telerik-mvc,telerik-open-access,Model View Controller,Telerik,Telerik Mvc,Telerik Open Access,我不熟悉Telerik OpenAccess ORM,并使用数据库优先的方法进行MVC项目。我在他们的网站上浏览了关于模型的教程视频: 我很想知道如何从Modal扩展域类和查询数据库?例如,我有一个生成的“Person”类&我用以下类扩展它: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MVCApplication { public par

我不熟悉Telerik OpenAccess ORM,并使用数据库优先的方法进行MVC项目。我在他们的网站上浏览了关于模型的教程视频:

我很想知道如何从Modal扩展域类和查询数据库?例如,我有一个生成的“Person”类&我用以下类扩展它:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVCApplication
{
    public partial class Person
    {
        public string PersonName
        {
            get
            {
                return this.FirstName + " " + this.LastName;
            }
        }
    }
}
这与上面视频中显示的示例非常相似。我很好奇是否可以从Person表或满足特定条件的Person对象集合中检索所有记录?我的“返回”查询将是怎样的?此扩展模型类中没有可用的dbContext:(

public List GetAllPeople()
{
//返回列表在这里
}
公共列表GetAllPeopleFromLocationA(int locationID)
{
//返回列表在这里
}

通常,域类不用于查询数据库,我建议您在域上下文的部分类中添加GetAllPeople和GetAllPeopleFromLocationA方法,如下所示:

public List<Person> GetAllPeople()
{
    return this.People.ToList();
}

public List<Person> GetAllPeopleFromLocationA(int locationID)
{
    return this.People.Where(p => p.LocationID == locationID).ToList();
}
public List<Person> GetAllPeople()
{
    return this.People.ToList();
}

public List<Person> GetAllPeopleFromLocationA(int locationID)
{
    return this.People.Where(p => p.LocationID == locationID).ToList();
}
using (YourContextName context = new YourContextName())
{
    foreach (Person person in context.GetAllPeople())
    {
        // you could access your custom person.PersonName property here
    }

    foreach (Person person in context.GetAllPeopleFromLocationA(someLocationID))
    {
        // you could access your custom person.PersonName property here
    }
}