快捷搜索:

NBear - 使用Entity Configurator设置实体元数据、生成

示例

本示例演示对一组承袭关系的实体的元数据设置及自动天生数据库创建脚本的历程。示例实体代码,包括天生的config文件和sql文件等都包孕鄙人载的源代码包的NBear\samples\Sample_Entity_Configuration_By_Entity_Configurator及其bin\Debug中。

如上图所示,在vs2005中应用内置的可视化类设计器设计实体布局如上,留意,所有的实体都是接口。关于若何创建简单的接口式实体,请拜见用户手册。对应的代码如下:

1  [Table(IsContract = true)]

2  public interface IdentableEntity : IEntity

3  {

4    [PrimaryKey]

5    int Id { get; set; }

6    string Name { get; set; }

7  }

8

9  [Table(IsContract = true)]

10  public interface Loginable : IEntity

11  {

12    string LoginId { get; set; }

13  }

14

15  [Table(IsContract = true)]

16  public interface PasswordLoginable : Loginable

17  {

18    string Password { get; set; }

19  }

20

21  [Table(IsContract = true)]

22  public interface PrivilegeAssignable : IEntity

23  {

24    int PrivilegeOwnerId { get; set; }

25  }

26

27  [Table("User", UpdateTableName = "User", UpdateExtendedOnly = true)]

28  public interface User : IdentableEntity, PrivilegeAssignable

29  {

30  }

31

32  [Table("select User.*, LocalUser.LoginId, LocalUser.Password from LocalUser inner join User on LocalUser.Id = User.Id", UpdateTableName = "LocalUser", IsView = true, UpdateExtendedOnly = true)]

33  public interface LocalUser : PasswordLoginable, User

34  {

35  }

36

37  [Table("select User.*, AgentUser.LoginId from AgentUser inner join User on AgentUser.Id = User.Id", UpdateTableName = "AgentUser", IsView = true, UpdateExtendedOnly = true)]

38  public interface AgentUser : Loginable, User

39  {

40  }

41

42  [Table("select User.* from GhostUser inner join User on GhostUser.Id = User.Id", UpdateTableName = "GhostUser", IsView = true, UpdateExtendedOnly = true)]

43  public interface GhostUser : User

44  {

45  }

46

47  [Table("UserGroup", UpdateTableName = "UserGroup", UpdateExtendedOnly = true)]

48  public interface UserGroup : IdentableEntity, PrivilegeAssignable

49  {

50    string Comment { get; set; }

51  }

共4页:

上一页1

2

3

4

下一页

您可能还会对下面的文章感兴趣: