我想實現一個更改日誌作爲建議在 Dev Express XAF T474899代碼遷移意外嘗試重命名錶
我使用由XAF新的解決方案嚮導生成的安全系統
我已經定義一些業務對象存儲更改日誌信息。
其中一個對象存儲指向用戶的鏈接
public virtual User User {get;組; }
在生成的代碼移植,我驚訝地看到向上()方法中添加以下
RenameTable(name: "dbo.UserRoles", newName: "RoleUsers");
DropPrimaryKey("dbo.RoleUsers");
AddPrimaryKey("dbo.RoleUsers", new[] { "Role_ID", "User_ID" });
在另一個場合,我發現在一個向上()
RenameTable(name: "dbo.EventResources", newName: "ResourceEvents");
// lots of other stuff
DropPrimaryKey("dbo.ResourceEvents");
AddPrimaryKey("dbo.ResourceEvents", new[] { "Resource_Key", "Event_ID" });
在以下兩種情況下創建實體的代碼都是Dev Express庫。
我交張貼了這個問題Dev Express Support
的開發快遞業務對象在DevExpress.Persistent.BaseImpl.EF定義;
我的DbContext語境指的是他們作爲
public DbSet<Role> Roles { get; set; }
public DbSet<User> Users { get; set; }
我自己的業務類包含
namespace SBD.JobTalk.Module.BusinessObjects
{
[NavigationItem("Configuration")]
[DisplayName("Staff")]
[DefaultProperty("Summary")]
[ImageName("BO_Employee")]
[Table("Staff")]
public class Staff : BasicBo
{
public Staff()
{
Person = new Person();
}
public virtual Person Person { get; set; }
[StringLength(100, ErrorMessage = "The field cannot exceed 100 characters. ")]
[scds.Index("IX_Staff_UserName", 1, IsUnique = true)]
public string UserName { get; set; }
[NotMapped]
public string Summary => $"{Person.FirstName} {Person.LastName}";
//public virtual User User { get; set; }
}
}
public abstract class BasicBo : IXafEntityObject
{
[Browsable(false)]
[Key]
public virtual int Id { get; set; }
public virtual void OnCreated()
{
}
public virtual void OnSaving()
{
}
public virtual void OnLoaded()
{
}
}
如果我取消註釋代碼有內部員工的用戶屬性,併產生遷移,遷移最多是
public override void Up()
{
RenameTable(name: "dbo.UserRoles", newName: "RoleUsers");
DropPrimaryKey("dbo.RoleUsers");
AddColumn("dbo.Staff", "User_ID", c => c.Int());
AddPrimaryKey("dbo.RoleUsers", new[] { "Role_ID", "User_ID" });
CreateIndex("dbo.Staff", "User_ID");
AddForeignKey("dbo.Staff", "User_ID", "dbo.Users", "ID");
}
[更新] 有趣的是有更多的開發快速的表比我第一個念頭。主鍵是Identity。
我覺得現在用標準認證創建之前開發快速添加允許/拒絕的能力(V16.1)
[更新] 當我創建了上述設置一個新的項目,這裏是的DbContext 。
using System;
using System.Data;
using System.Linq;
using System.Data.Entity;
using System.Data.Common;
using System.Data.Entity.Core.Objects;
using System.Data.Entity.Infrastructure;
using System.ComponentModel;
using DevExpress.ExpressApp.EF.Updating;
using DevExpress.Persistent.BaseImpl.EF;
using DevExpress.Persistent.BaseImpl.EF.PermissionPolicy;
namespace XafApplication1.Module.BusinessObjects {
public class XafApplication1DbContext : DbContext {
public XafApplication1DbContext(String connectionString)
: base(connectionString) {
}
public XafApplication1DbContext(DbConnection connection)
: base(connection, false) {
}
public XafApplication1DbContext()
: base("name=ConnectionString") {
}
public DbSet<ModuleInfo> ModulesInfo { get; set; }
public DbSet<PermissionPolicyRole> Roles { get; set; }
public DbSet<PermissionPolicyTypePermissionObject> TypePermissionObjects { get; set; }
public DbSet<PermissionPolicyUser> Users { get; set; }
public DbSet<ModelDifference> ModelDifferences { get; set; }
public DbSet<ModelDifferenceAspect> ModelDifferenceAspects { get; set; }
}
}
Cross發佈到Dev Express https://www.devexpress.com/Support/Center/Question/Details/T486359 –
顯示用戶類。那是身份嗎? Context和DbSets可能也有幫助。 –
謝謝@SteveGreene我已更新問題 –