同志们,任何人都可以帮助我,实体框架5似乎没有ApplyCurrentValues()方法.是否有另一种方法来更新实体框架v5中的数据库对象.这是我想要做的
odc.Accounts.Attach(new Account { AccountID = account.AccountID });
odc.Accounts.ApplyCurrentValues(account);
odc.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
但是我在ApplyCurrentValues()行中遇到了编译错误
我一直在我的mvc项目中使用实体框架代码首次迁移.但最近在修改我的模型类并添加新模型后,当我尝试在包管理器控制台中使用add-migration时,我不断收到此错误:'对象引用未设置为对象的实例'我正在使用entity framework version 5,当我尝试使用版本6,但它不会看到我的DbContext,这是我的堆栈跟踪,请欢迎每一个建议.
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EdmEntityType entityType, EdmModel model)
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntities(EdmModel model)
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml)
at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext context)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud) 试图实现的目标是创建一个如下所示的类。
public class Purse
{
public decimal AvaliableBalance { get; protected set; }
public decimal PendingBalance { get; protected set; }
public decimal TotalBalance { get; protected set; }
}
Run Code Online (Sandbox Code Playgroud)
但是,我想知道实体框架是否能够填充此类。如果是这样,怎么办?
基本上,要完成的工作是在代码端直接限制对这些属性的写操作,但是我希望Entity Framework能够写这些属性。我想通过一个唯一的目的是通过写一个方法来公开这些属性的设置方法值(即:经过一些处理后)。