0
Using Maxtoroq's DBExtensions how can we map an object having list of elements as child property 
using just one sql builder?

My sample DB structure 

Employee
   EmployeeId
   FirstName
   LastName

Department
 DeptId
 DeptName

EmployeeDepartment
  EmployeeId
  DeptId


My POCO 

class Department{

 public int DeptId {get;set;}

 public string DeptName {get;set;}
}

class Employee {

public void Employee(){
  Depts = new List<Department>();
}

  public int EmployeeId {get;set;}

  public string FirstName {get;set;}

  public string LastName {get;set;}

  public List<Department> Depts {get;set;}
}

现在我想创建用户的实例,包括他与使用 SqlBuilder 关联的所有部门,方法是一次性运行对 db 的查询(而不是多次调用 db)。

我怎样才能做到这一点?

4

1 回答 1

1

AFAIK,没有可以在单个数据库调用中加载包括一对多关联的实体的 ORM。

您可以在 DbExtensions 中执行此操作,但您可以使用 Database/SqlTable 代替 SqlBuilder:

class MyDatabase : Database {

   public SqlTable<Employee> Employees {
      get { return Table<Employee>(); }
   }

   public MyDatabase()
      : base("name=MyDatabase") { }
}

var db = new MyDatabase();

Employee emp = db.Employees
   .Include("Depts")
   .Find(1);
于 2014-09-08T14:52:06.827 回答