- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试在我的数据库上下文中保存一个对象时,我遇到了这个 Entity Framework 错误。我不知道从哪里开始寻找。
这里会发生什么?
如何找出问题所在?
谢谢。
{System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'Exception' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'AssemblyName' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'CultureInfo' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'DateTimeFormatInfo' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'IdentityReference' has no key defined. Define the key for this EntityType.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'Exceptions' is based on type 'Exception' that has no keys defined.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'AssemblyNames' is based on type 'AssemblyName' that has no keys defined.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'CultureInfoes' is based on type 'CultureInfo' that has no keys defined.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'DateTimeFormatInfoes' is based on type 'DateTimeFormatInfo' that has no keys defined.
\tSystem.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'IdentityReferences' is based on type 'IdentityReference' that has no keys defined.
at System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.ValidateAndSerializeCsdl(EdmModel model, XmlWriter writer)
at System.Data.Entity.ModelConfiguration.Edm.EdmModelExtensions.ValidateCsdl(EdmModel model)
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
at System.Data.Entity.DbSet`1.Add(TEntity entity)
at MVCDaemon.Controllers.AwardBadgesController.FromUnprocessedEvents() in Hobby Stuff\Hehe\Hehe.Daemon\Controllers\AwardBadgesController.cs:line 58}
和我的其他东西:
DaemonDB.Tasks.Add(T);
和
public class DaemonDBContext : DbContext
{
public DaemonDBContext() : base("DefaultConnection") { }
//Collections also in BaseDBContext:
public DbSet<Badge> Badges { get; set; }
public DbSet<BadgeGroup> BadgeGroups { get; set; }
public DbSet<Event> Events { get; set; }
//Collections only in DaemonDBContext
public DbSet<EventCheckedForBadgeReward> EventCheckedForBadgeReward { get; set; }
public DbSet<Task> Tasks { get; set; }
}
和
public class Task
{
public int ID { get; set; }
public string FriendlyTitle { get; set; }
public DateTime TimeOfExecution { get; set; }
public TimeSpan LengthOfExecution { get; set; }
public Stopwatch StopWatch;
public Exception ExceptionEncountered { get; set; }
public Task() {
TimeOfExecution = DateTime.Now;
}
public void StartStopwatch()
{
StopWatch = Stopwatch.StartNew();
StopWatch.Start();
}
public void StopStopwatch()
{
StopWatch.Stop();
}
public string GetStatusAsFriendly()
{
return ExceptionEncountered == null ? "Success" : "Failed";
}
}
最佳答案
必须在某些属性上使用 [NotMapped] 属性。
关于c# - Entity Framework 验证错误没有定义键。为此 EntityType 定义键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17355666/
我刚刚开始使用 BreezeJS,并将 HotTowel 模板与 Asp.Net Web Api 和 EF 结合使用 我已经尝试使用 manager.getEntityByKey 检索记录,使用 ht
我的代码在 Solution.Models.Worker 中: using System; using System.Collections.Generic; using System.Linq; u
请帮我解决这个问题。我已经坐了 2 天了,不知道我哪里做错了。我在下面看过这篇文章: EntityType 'MyProfile' has no key defined. Define the key
我的模型类是 public class posts { [Key] public int AuthorId; public string author_first_name;
我不确定为什么会收到此错误消息。我在我的 sql 数据库中为其定义了一个主键。这是我的代码: [HttpPost] public ActionResult Register(RegisterM
这个问题在这里已经有了答案: EntityType has no key defined error (13 个回答) 5年前关闭。 开发一个基本的 ASP.net MVC 4 应用程序。它是一个简单
我正在使用 Entity Framework Code First 和 MVC 5。当我使用个人用户帐户身份验证创建应用程序时,我获得了一个帐户 Controller 以及所有必需的类和代码,需要使个
我有 80 个表的数据库(每个表都有主键)。我已经从数据库(添加 - 新项目 - ADO.NET 实体数据模型)在 ASP.NET MVC 项目中生成了模型。但是在生成的模型中,我有 80 个类(对于
我有一个接收参数的操作,我想打印出所有结果 public ActionResult MusicaGenero(string genero) { //should return
我正在使用 EF Code First 和 Data Scaffolding 并且有一个包含类型属性的实体 public System.Drawing.Image Image { get; set;
在 Entity Framework 4.3.1 中,我有以下模型,它们运行良好: public class BaseUser { [Key] [MaxLength(100)]
我有一个 Entity Framework Code First 模型,其中有一个未映射的列,我仍然希望在服务器和客户端之间保留该列。该模型看起来与此类似,但具有更多属性: public class
我正在创建一个应用程序,用户可以在其中通过 Facebook oAuth 登录,然后设置歌曲列表。我收到以下错误消息: BandFinderCsharp.Models.IdentityUserLogi
C# 代码(EF6 代码优先): public class ProjectSourceProject { [Key, Column(Order = 0)] //[Key, Column
我有两个类 User.php 和 Group.php,它们是从 fosuserbundle 中定义的类扩展而来的。 除此之外,我在它们之间有一个 ManyToMany 关系。 该应用程序的想法是,当我
在我的项目中,我使用一个表(用户任务)中的数据来描述创建预订记录(预订表)的数据。在表单中,我尝试接收选择列表。运行时报错: Expected argument of type "Doctrine\O
Controller : using System; using System.Collections.Generic; using System.Linq; using System.Web; us
我已将 Symfony 的 EntityType 扩展为 UserChooserType 以用于我的 User 实体和 Select2。 UserChooserType 的选择列表来自 ldap 查询
我有一个带有 EntityType 类型字段的表单: $builder->add( 'contacts', EntityType::class,
我有一个像这样的表单字段: $form->add('tags', EntityType:class, array( 'class' => Tags::class, 'multiple'
我是一名优秀的程序员,十分优秀!