NBear - 使用Entity Configurator设置实体元数据、生成数据库创建脚本2010-05-20 cnblogs.com teddyma Teddy"s Know示例本示例演示对一组继承关系的实体的元数据设置及自动生成数据库创建脚本的过程。示例实体代码,包括生成的config文件和sql文件等都包含在下载的源代码包的NBearsamplesSample_Entity_Configuration_By_Entity_Configurator及其binDebug中。

如上图所示,在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 }