bltoolkit与存储过程执行的关联

时间:2012-03-26 10:12:25

标签: associations bltoolkit proc

我有两个实体:

[TableName("is_userrole")]



public class UserRole
  {
      [MapField("id"), PrimaryKey, Identity,
      public Guid id;
      [NotNull]
      public string Name;       
  }    
[TableName("is_users")]
  public class User
  {
      [MapField("id"), PrimaryKey, Identity,
NonUpdatable]
      public Guid Id;
      [NotNull]
      public string Name;
      [NotNull]
      public string Login;
      [NotNull]
      public string Password;

      public Guid UserRole_Id;    
      [Association(ThisKey = "UserRole_Id", OtherKey = "Id",
CanBeNull = false)]
      public UserRole UserRole;
  }    

和sql server上的存储过程,它从查询中获取数据

[从is_users u中选择你。,r。    内部联接is_userrole r on u.userrole_id = r.id]

如果我使用像

这样的linq查询

var query =来自db.User中的u                               选择新的                               {                                   u.Id,                                   u.Login,                                   u.Password,                                   u.UserRole_Id,                                   u.UserRole                               };

关联填充,但如果我执行程序只有父对象(即用户)填写 如何在bltoolkit.net中与存储过程建立关联? 或者它只能手动实现?

感谢。

2 个答案:

答案 0 :(得分:0)

好的,所以我对此没有任何经验,但我很快就看了单元测试,看起来MapResultSet可以帮助你

单元测试在这里 - >单元测试\ CS \映射\ ResultSetTest.cs

答案 1 :(得分:0)

AssosiationAttribute仅用于Linq表达式。

要点知道:BLT没有“隐藏”行动,例如。如果您将linq代码更改为:db.User.ToList(),您将看到UserProperty未填充。在您的示例填充中,因为您已经说过在select clausue中完成填充,而Association仅用于在SQL中构建正确的“INNER JOIN”。