我有3个非常简单的模型。
public abstract class User : IEntity
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[StringLength(40)]
public string UserName { get; set; }
[StringLength(40)]
public string FirstName { get; set; }
[StringLength(40)]
public string LastName { get; set; }
/// <summary>
/// Password as SHA256
/// </summary>
[StringLength(64)]
public string Password { get; set; }
public virtual ICollection<SocialAccount> SocialLogins { get; set; }
}
public class Student : User
{
public string Test { get; set; }
}
public class Teacher : User
{
public string Qwert { get; set; }
}
执行代码
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<RelationalDatabase>());
var rel = new RelationalDatabase();
rel.Users.Add(
new Teacher
{
FirstName = "Hayri",
LastName = "Tüfekçilerli",
UserName = "hayri",
Password = "asdnfaksjnfkasjfn"
});
rel.SaveChanges();
错误:
Nancy.RequestExecutionException:哦,不! ---&GT; System.NotSupportedException:类型&#39; GoAndTeach.Models.Student&#39;和 类型&#39; GoAndTeach.Models.Student&#39;两者都有相同的简单名称 &#39;学生&#39;所以不能在同一型号中使用。所有类型的 给定模型必须具有唯一的简单名称。使用&#39; NotMappedAttribute&#39;要么 在Code First Fluent API中调用Ignore以明确排除a 属性或类型来自模型。在 System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.GetExistingEdmType [的EntityType] (System.Data.Entity.Core.Metadata.Edm.EdmModel model,System.Type type)[0x00000] in:0 at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType (System.Type类型)[0x00000] in:0 at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapDerivedTypes (System.Type类型,System.Data.Entity.Core.Metadata.Edm.EntityType entityType)[0x00000] in:0 at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.MapEntityType (System.Type类型)[0x00000] in:0 at System.Data.Entity.DbModelBuilder +&lt;&gt; c_ DisplayClassd.b _7(System.Type type)[0x00000] in:0 at System.Linq.Enumerable + c__Iterator33
1[System.Type].MoveNext () [0x00000] in :0 at System.Data.Entity.Utilities.IEnumerableExtensions.Each[Type] (IEnumerable
1 ts,System.Action1 action) [0x00000] in :0 at System.Data.Entity.DbModelBuilder.MapTypes (System.Data.Entity.Core.Metadata.Edm.EdmModel model) [0x00000] in :0 at System.Data.Entity.DbModelBuilder.Build (System.Data.Entity.Core.Common.DbProviderManifest providerManifest, System.Data.Entity.Infrastructure.DbProviderInfo providerInfo) [0x00000] in :0 at System.Data.Entity.DbModelBuilder.Build (System.Data.Common.DbConnection providerConnection) [0x00000] in :0
2 [System.Data.Entity.Internal.LazyInternalContext,System.Data.Entity.Infrastructure.DbCompiledModel] .GetValue (System.Data.Entity.Internal.LazyInternalContext输入)[0x00000] in :0 ---内部异常堆栈跟踪结束--- at Nancy.NancyEngine.InvokeOnErrorHook(Nancy.NancyContext context, Nancy.ErrorPipeline管道,System.Exception ex)[0x00000] in:0
at System.Data.Entity.Internal.LazyInternalContext.CreateModel (System.Data.Entity.Internal.LazyInternalContext internalContext) [0x00000] in :0 at System.Data.Entity.Internal.RetryLazy
相同的程序集,相同的代码适用于.Net Framework 4.5。在单声道上,我得到了那个奇怪的错误。
实体框架版本:6.1 MysqlConnector版本:6.8.3.2
我该如何解决这个问题?