[英]How to specify a table type using EF6 Fluent API for MySQL?
所以我使用EF6的Fluent API在我的代碼第一個應用程序中指定實體屬性。 但是我想為我的一個實體指定一個表類型,是否可以通過api執行此操作?
ApplicationDbContext:
public class ApplicationUser : IdentityUser
{
public string CreatedBy { get; set; }
public DateTime Active { get; set; }
public DateTime RememberMeTimeOut { get; set; }
public int CentralPermissionUserID { get; set; }
public virtual ICollection<UserLogs> UserLogs { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DBContext", throwIfV1Schema: false)
{
}
public DbSet<UserLogs> UserLogs { get; set; }
public DbSet<Supplier> Supplier { get; set; }
public DbSet<SupplierArchive> SupplierArchive { get; set; }
public DbSet<MenuStatsSummary> MenuStatsSummary { get; set; }
public DbSet<Pot> Pots { get; set; }
public DbSet<PotDupeStandards> PotDupeStandards { get; set; }
public DbSet<DupeStandards> DupeStandards { get; set; }
public DbSet<DupeStandardMapping> DupeStandardMapping { get; set; }
public DbSet<DupeData> DupeData { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
#region Application User
modelBuilder.Entity<ApplicationUser>().Property(u => u.UserName).HasMaxLength(255);
modelBuilder.Entity<ApplicationUser>().Property(u => u.Email).HasMaxLength(255);
modelBuilder.Entity<ApplicationUser>().Property(u => u.CreatedBy).HasMaxLength(50).IsRequired();
modelBuilder.Entity<ApplicationUser>().Property(u => u.CentralPermissionUserID).IsRequired();
modelBuilder.Entity<ApplicationUser>()
.HasMany(u => u.UserLogs)
.WithRequired(u => u.User)
.HasForeignKey(u => u.UserID)
.WillCascadeOnDelete(true);
modelBuilder.Entity<ApplicationUser>()
.Property(u => u.Email)
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UQ_Email") { IsUnique = true }));
modelBuilder.Entity<ApplicationUser>()
.Property(u => u.UserName)
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UQ_UserName") { IsUnique = true }));
#endregion
所以我想說我想將ApplicationUser
表設置為使用MyISAM
表引擎,我該怎么做呢?
你不能這樣做 .B'cos你可以使用Fluent API
來配置你的域類。但是fluent API
對特定數據庫提供者的詳細信息一無所知。它是一個通用的API,用於將POCO
類映射到tables
及其columns
。
MYSQL
是一個關系數據庫提供者,它擁有許多特定於提供者的組件。例如,它有不同的表引擎。 比如InnoDB
, MyISAM
等。但是Fluent Api只是一個映射器,對數據庫提供者的具體實現一無所知。
為此,您需要創建一個遷移,然后在Up方法中編寫自己的Sql命令,如下所示:
Sql("DROP TABLE Badger");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.