示例
本示例演示對一組繼承關系的實體的元數據設置及自動生成數據庫創建腳本的過程。示例實體代碼,包括生成的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 }