Entity Framework Linq update data not working

I want to update the entity object record but it do not show exception but it do not update the record. in issue_detail objetct previously it contains a null value, after user update data it calls the below method public Boolean bookReturnedUpdate(Issue_Detail issue) { BookController bookController = new BookController(); int bookID = (int) issue.book_id; Book_Deta

实体框架Linq更新数据不起作用

我想更新实体对象记录,但它不显示异常,但不更新记录。 在issue_detail objetct中它以前包含一个空值,在用户更新数据之后它会调用下面的方法 public Boolean bookReturnedUpdate(Issue_Detail issue) { BookController bookController = new BookController(); int bookID = (int) issue.book_id; Book_Detail book = bookController.findByBookID(bookID); int noOfCopies = (int) bo

Entity Framework update virtual property directly without creating new record

Here is a simple entity: public class Customer : Entity { public virtual Location Location { get; set; } } Now suppose we have a customer already: var customer = new Customer() {Location = new Location("China")}; and now we want to update his location: var customer = context.Customers.First(x => x.Location.Country == "China"); customer.Location = new Location("America"); context.SaveC

实体框架直接更新虚拟财产而不创建新记录

这是一个简单的实体: public class Customer : Entity { public virtual Location Location { get; set; } } 现在假设我们已经有客户: var customer = new Customer() {Location = new Location("China")}; 现在我们想更新他的位置: var customer = context.Customers.First(x => x.Location.Country == "China"); customer.Location = new Location("America"); context.SaveChanges(); 现在当我查看数据库时,

Changes to DbContext not saved

I have created a database and then an MVC solution using VisualStudio Exrpess 2013 for WEB and I created a ViewModel to display an Edit view with dropdown lists. The view model includes just the property 'parlists' of type PartnerList, which is the model representing the main table of the database, and 2 properties of type SelectList which I use to create the dropdown lists in the view.

未保存对DbContext的更改

我创建了一个数据库,然后使用VisualStudio Exrpess 2013 for WEB创建了一个MVC解决方案,并创建了一个ViewModel以显示带有下拉列表的编辑视图。 视图模型只包含PartnerList类型的属性“parlists”,它是表示数据库主表的模型,以及两个用于在视图中创建下拉列表的SelectList类型属性。 viewmodel的代码如下所示: public class FileStatusEdit { public SelectList HoldingsStatus { get; set; } public SelectList Rea

Entity Framework 6.1 Updating a Subset of a Record

I have a view model that encapsulates only some of the database model properties. These properties contained by the view model are the only properties I want to update. I want the other properties to preserve their value. During my research I found this answer which appears to be perfect for my needs however, despite my best efforts, I cannot get the code to work as expected. Here is an iso

实体框架6.1更新记录的子集

我有一个只封装了一些数据库模型属性的视图模型。 视图模型包含的这些属性是我想要更新的唯一属性。 我希望其他的财产保持其价值。 在我的研究中,我发现这个答案看起来对我的需求来说是完美的,尽管我尽了最大的努力,但我无法让代码按预期工作。 这是我想到的一个孤立的例子: static void Main() { // Person with ID 1 already exists in database. // 1. Update the Age and Name. Person person = new

Entity Framework create update query unnecessary

I am trying to update record with LINQ to SQL but in some case value is same as original value then also Enitty framework create Update query unnecessary. var objForupdate = context.temp.FirstOrDefault(); if(objForupdate != null) { objForupdate.Name = "VJ"; // Original Value also "VJ" } // Create update query for above. context.SaveChanges(); Updated Hey Steven Wood Here I have

实体框架创建更新查询不必要

我试图用LINQ to SQL更新记录,但在某些情况下,值与原始值相同,然后Enitty框架创建更新查询不必要。 var objForupdate = context.temp.FirstOrDefault(); if(objForupdate != null) { objForupdate.Name = "VJ"; // Original Value also "VJ" } // Create update query for above. context.SaveChanges(); 更新了嘿史蒂文伍德 在这里我有我的数据库有20个字段的场景。 有时某些数据与原始数据相同,那么En

Updating SQL bit column from Entity Framework

I'm having an issue updating a 'bit' column in a SQL database, using C# and Entity Framework. I have a 'Settings' table with a NOT NULL bit column named 'Active'. When I create a record in the table and specify 'Active' in code as 'true' or 'false', the record in the database that's created is accurate and the 'Active' column cont

从实体框架更新SQL位列

我在使用C#和Entity Framework更新SQL数据库中的'bit'列时遇到问题。 我有一个名为'Active'的NOT NULL位列的'Settings'表。 当我在表中创建一条记录并在代码中指定'有效'为'true'或'false'时,创建的数据库中的记录是准确的,'Active'列包含代码中指定的正确值。 当我更新记录并在代码中将'Active'从'false'更改为'true'时,该功能也起作

Exclude Property on Update in Entity Framework

I've been looking for a proper way to mark a property to NOT be changed when updating a model in MVC. For example, let's take this small model: class Model { [Key] public Guid Id {get; set;} public Guid Token {get; set;} //... lots of properties here ... } then the edit method MVC creates looks like this: [HttpPost] public ActionResult Edit(Model model) { if (Mod

在实体框架中更新排除属性

在MVC中更新模型时,我一直在寻找一种合适的方法来标记属性不被更改。 例如,我们来看看这个小模型: class Model { [Key] public Guid Id {get; set;} public Guid Token {get; set;} //... lots of properties here ... } 那么编辑方法MVC创建如下所示: [HttpPost] public ActionResult Edit(Model model) { if (ModelState.IsValid) { db.Entry(model).State = EntityState.Modified;

Detached entities causing duplicate ID issues

I have very limited experience using EF4. I am successfully deserializing entities from a webservice in a detached state, and I now would like to save to the database. When SaveChanges is used I get the following exception: System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Violation of

分离的实体导致重复的ID问题

我使用EF4的经验非常有限。 我成功地从分离状态的web服务反序列化实体,现在我想保存到数据库。 当使用SaveChanges时,我得到以下异常: System.Data.UpdateException:更新条目时发生错误。 详情请参阅内部例外。 ---> System.Data.SqlClient.SqlException:违反PRIMARY KEY约束'[主键约束名]'。 无法在对象'[关联表名]'中插入重复键。 重复的键值是(1)。 该语句已终止。 我试图保存的实体将相

To detach or not to detach? entity framework IBindingList issue

MY PROBLEM : I have a listobject that I want to persist to sql server and when I call .SaveChanges() on Entity Framework it will fail because some objects in the context are not valid. MY QUESTION: HOW DO I PERSIST ONLY VALID CHANGES? I'll work on UI informing the client as to those that are not valid. I'm working with a VSTO Excel workbook project and I'm trying to manage data c

分离还是不分离? 实体框架IBindingList问题

我的问题 :我有一个listobject,我想坚持sql服务器,当我调用Entity Framework上的.SaveChanges()时,它会失败,因为上下文中的某些对象无效。 我的问题:我如何保持有效更改? 我将在UI上通知客户那些无效的客户端。 我正在处理一个VSTO Excel工作簿项目,并试图管理ListObject上的数据垃圾。 我有一个POCO类和实体框架。 我将实体作为事件的IBindingList对象传递给ListObject。 当我去.SaveChanges()它的实体崩

Entity Framework Timeouts

I am getting timeouts using the Entity Framework (EF) when using a function import that takes over 30 seconds to complete. I tried the following and have not been able to resolve this issue: I added Default Command Timeout=300000 to the connection string in the App.Config file in the project that has the EDMX file as suggested here. This is what my connection string looks like: <add

实体框架超时

当使用需要30秒才能完成的功能导入时,我使用实体框架(EF)获取超时。 我尝试了以下方法,但无法解决此问题: 按照此处所建议的,将EDMX文件的项目中的App.Config文件中的连接字符串添加为Default Command Timeout=300000 。 这就是我的连接字符串的样子: <add name="MyEntityConnectionString" connectionString="metadata=res://*/MyEntities.csdl|res://*/MyEntities.ssdl| res://*/MyEntities.ms