草庐IT

Entity-Framework

全部标签

c# - ASP.NET Identity - 不支持每种类型的多个对象集

我在我的应用程序中使用ASP.NETIdentity时遇到错误。Multipleobjectsetspertypearenotsupported.Theobjectsets'IdentityUsers'and'Users'canbothcontaininstancesoftype'RecommendationPlatform.Models.ApplicationUser'.我在StackOverflow中看到了一些关于这个错误的问题。所有指示在相同类型的两个DbSet对象上。但是在我的DbContext中,没有相同类型的DbSets。登录时FindAsync()方法抛出异常。if(Mo

c# - DbContext 丢弃更改而不处理

我有一个桌面客户端应用程序,它使用模态窗口来设置分层对象的属性。由于这是一个客户端应用程序并且对DbContext的访问不是线程化的,因此我在主窗体上使用了一个长时间运行的上下文,该上下文传递给模态子级。这些模态窗口使用PropertyGrid来显示实体属性,并且还有取消按钮。如果修改了任何数据并按下了取消按钮,则更改会反射(reflect)在父窗体中(我无法在其中处理DbContext对象)。如果未调用DbContext.SaveChanges()方法,是否可以放弃所做的任何更改?更新EntityFramework版本4.4。 最佳答案

c# - DbContext 丢弃更改而不处理

我有一个桌面客户端应用程序,它使用模态窗口来设置分层对象的属性。由于这是一个客户端应用程序并且对DbContext的访问不是线程化的,因此我在主窗体上使用了一个长时间运行的上下文,该上下文传递给模态子级。这些模态窗口使用PropertyGrid来显示实体属性,并且还有取消按钮。如果修改了任何数据并按下了取消按钮,则更改会反射(reflect)在父窗体中(我无法在其中处理DbContext对象)。如果未调用DbContext.SaveChanges()方法,是否可以放弃所做的任何更改?更新EntityFramework版本4.4。 最佳答案

c# - Entity Framework Include() 强类型

有没有办法使用System.Data.Entity.Include方法使其成为强类型?在下面的方法中,Escalation是一个ICollection。publicIEnumerableGetAllTypes(){Database.Configuration.LazyLoadingEnabled=false;returnDatabase.EscalationTypes.Include("Escalation").Include("Escalation.Primary").Include("Escalation.Backup").Include("Escalation.Primary.C

c# - Entity Framework Include() 强类型

有没有办法使用System.Data.Entity.Include方法使其成为强类型?在下面的方法中,Escalation是一个ICollection。publicIEnumerableGetAllTypes(){Database.Configuration.LazyLoadingEnabled=false;returnDatabase.EscalationTypes.Include("Escalation").Include("Escalation.Primary").Include("Escalation.Backup").Include("Escalation.Primary.C

c# - ASP.NET 添加迁移 'composite primary key error' 如何使用 Fluent API

您好,我正在创建Web应用程序,并且已经安装了Microsoft.entityFrameworkCore和Microsoft.entityFrameworkCore.Tools。在包管理器控制台中执行添加迁移的过程中出现错误“System.InvalidOperationException:实体类型‘Attends’具有用数据注释定义的复合主键。要设置复合主键,请使用流畅的API”这是我在实体文件夹中的代码。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel.DataAnnotations;usi

c# - ASP.NET 添加迁移 'composite primary key error' 如何使用 Fluent API

您好,我正在创建Web应用程序,并且已经安装了Microsoft.entityFrameworkCore和Microsoft.entityFrameworkCore.Tools。在包管理器控制台中执行添加迁移的过程中出现错误“System.InvalidOperationException:实体类型‘Attends’具有用数据注释定义的复合主键。要设置复合主键,请使用流畅的API”这是我在实体文件夹中的代码。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel.DataAnnotations;usi

c# - Entity Framework - 在事务内检索 'SaveChanges' 之前的 ID

在EntityFramework中-在调用“SaveChanges”之前,是否有任何方法可以在事务中检索新创建的ID(身份)?我需要第二个插入的ID,但它始终返回为0...ObjectContextobjectContext=((IObjectContextAdapter)context).ObjectContext;objectContext.Connection.Open();using(vartransaction=objectContext.Connection.BeginTransaction()){foreach(tblTestentityinsaveItems){this

c# - Entity Framework - 在事务内检索 'SaveChanges' 之前的 ID

在EntityFramework中-在调用“SaveChanges”之前,是否有任何方法可以在事务中检索新创建的ID(身份)?我需要第二个插入的ID,但它始终返回为0...ObjectContextobjectContext=((IObjectContextAdapter)context).ObjectContext;objectContext.Connection.Open();using(vartransaction=objectContext.Connection.BeginTransaction()){foreach(tblTestentityinsaveItems){this

c# - CodeFirst EF4.1 MVC Against legacy database - 多重性冲突

无论我以何种方式混合,它都会给我错误。当我不断收到这些错误时,我感觉我遗漏了一些明显的东西。Oneormorevalidationerrorsweredetectedduringmodelgeneration:System.Data.Edm.EdmAssociationType::MultiplicityconflictswiththereferentialconstraintinRole'Venue_Courses_Source'inrelationship'Venue_Courses'.BecauseallofthepropertiesintheDependentRoleareno