首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

NBear Entity Configurator 實戰:視覺化設置實體元數據與自動生成資料庫建立腳本

     編輯:關於ASP.NET

本示例演示對一組繼承關係實體進行視覺化元數據配置,並自動生成資料庫建立腳本。完整代碼含配置檔與 SQL 腳本位於原始碼包 NBear\samples\Sample_Entity_Configuration_By_Entity_Configurator。

視覺化設計介面

VS2005 類別設計器視覺化介面

所有實體均為介面,使用 VS2005 內建類別設計器設計結構。

實體介面定義代碼

[Table(IsContract = true)]
public interface IdentableEntity : IEntity {
  [PrimaryKey] int Id { get; set; }
  string Name { get; set; }
}

[Table(IsContract = true)]
public interface Loginable : IEntity {
  string LoginId { get; set; }
}

[Table(IsContract = true)]
public interface PasswordLoginable : Loginable {
  string Password { get; set; }
}

[Table(IsContract = true)]
public interface PrivilegeAssignable : IEntity {
  int PrivilegeOwnerId { get; set; }
}

[Table("User", UpdateTableName = "User", UpdateExtendedOnly = true)]
public interface User : IdentableEntity, PrivilegeAssignable { }

[Table("select User.*, LocalUser.LoginId, LocalUser.Password from LocalUser inner join User on LocalUser.Id = User.Id", UpdateTableName = "LocalUser", IsView = true, UpdateExtendedOnly = true)]
public interface LocalUser : PasswordLoginable, User { }

[Table("select User.*, AgentUser.LoginId from AgentUser inner join User on AgentUser.Id = User.Id", UpdateTableName = "AgentUser", IsView = true, UpdateExtendedOnly = true)]
public interface AgentUser : Loginable, User { }

[Table("select User.* from GhostUser inner join User on GhostUser.Id = User.Id", UpdateTableName = "GhostUser", IsView = true, UpdateExtendedOnly = true)]
public interface GhostUser : User { }

[Table("UserGroup", UpdateTableName = "UserGroup", UpdateExtendedOnly = true)]
public interface UserGroup : IdentableEntity, PrivilegeAssignable {
  string Comment { get; set; }
}

透過 Entity Configurator 載入組件、設置元數據,點擊「Code → Generate EntityQuery Code」即可生成強型別查詢代碼,同步產出資料庫建立腳本,實現模型驅動開發。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved