MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
You could use try..catch..or check Quick Watch window in controller to look for the cause.
I already did this.
As I see the The Author_id field is required.
This is the main drawback of EF, if you want to update only few fields you have to update all fields in database table. (When you use Controller with view and entity framework).
I am looking for the solution that any fields don't have any compulsion. Fields should be free and independent for any (CRUD) operations.
any way Thanks
It is our choices, that show what we truly are, far more than our abilities.
This is the main drawback of EF, if you want to update only few fields you have to update all fields in database table. (When you use Controller with view and entity framework).
All ORM(s) work in the same manner when it comes to taking a persistence object and persisting it to the database table, which it's either all or nothing.
I am looking for the solution that any fields don't have any compulsion. Fields should be free and independent for any (CRUD) operations.
You can't do it with using a ADO.NET datatable either
The only way you could do such a thing would be able to develop a persistence object that kept its state, and it also kept all the properties states within the object for when logic you wrote to know when the persistence object was in a dirty state and
what properties in the object were in a dirty state in order to formulate dynamic T-SQL based on the persistence object's state and the state of properties within the persistence object.
If you find the post has answered your issue, then please mark post as 'answered'.
This is the main drawback of EF, if you want to update only few fields you have to update all fields in database table. (When you use Controller with view and entity framework).
I am looking for the solution that any fields don't have any compulsion. Fields should be free and independent for any (CRUD) operations.
You are assuming how EF works rather than taking the time to understand how it works. Anyway, the solution (programming pattern) was covered in your threads from yesterday.
This is the main drawback of EF, if you want to update only few fields you have to update all fields in database table. (When you use Controller with view and entity framework).
No,EF will not be so rigid.There are definitely other ways to implement your function.
According to your previous post,
I suggest you could use TryUpdateModel,because the Bind attribute clears out any pre-existing data in fields not listed in the Include parameter.
[HttpPost, ActionName("Edit")]
[ValidateAntiForgeryToken]
public ActionResult EditPost(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var studentToUpdate = db.Students.Find(id);
if (TryUpdateModel(studentToUpdate, "",
new string[] { "LastName", "FirstMidName", "EnrollmentDate" })) //you want to be updateable by the Edit page are whitelisted in the TryUpdateModel parameters.
{
try
{
db.SaveChanges();
return RedirectToAction("Index");
}
catch (DataException /* dex */)
{
//Log the error (uncomment dex variable name and add a line here to write a log.
ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
}
}
return View(studentToUpdate);
}
More details about Bind,TryUpdateModel and so on,you could refer to:
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
[HttpPost]
public ActionResult Edit(OTBandModel OTBand)
{
try
{
OTBand.ModifiedBy = Convert.ToInt32(Session["AdminID"].ToString());
DataAccessLayer db = new DataAccessLayer();
db.OTBand_Update(OTBand);
return RedirectToAction("Index");
}
catch (Exception ex)
{
throw;
}
}
Below is my Store Procedure
IF @Case = 2 -- update
BEGIN
UPDATE OT_Band_Master
SET vcname =@vcname ,vcrate_phour=@vcrate_phour,datemodi=GetDate(),updatedby=@updatedby
WHERE bigid=@bigid
END
But I did not understand why you said that with ADO.Net it can not be done. May be you are trying to say something else or might be possible I misunderstood.
It is our choices, that show what we truly are, far more than our abilities.
But I did not understand why you said that with ADO.Net it can not be done. May be you are trying to say something else or might be possible I misunderstood.
I don't see an ADO.NET tableadapter or a dataadapter along with a dataset and datatable being used in your code, which the 'all or nothing' statement would apply for data persistent using the technology in the scenario. ADO.NET would persist the data from
the datatable row and doing it column by column to the database table not concerned if the data actually changed or not for any given datatable row and column within the dataset
No matter how you use the ADO.NET datatable, there is sill no way that you can determine that data in a datatable row and column was modified and code is only checking for a modified column that will be persisted to a database table using an adapter, which
is not unlike using an EF entity object where the persistence properties in the object are not cheeked as to what property changed with T-SQL generated for only changed data in properties by the EF engine. EF doesn't care if a property in the object has
changed or not The same logic is applied to a datatable and T-SQL generated by the usage of a datatable sitting inside a dataset using an adapter or a helper that is generating the T-SQL
In either case in using a data container such as an EF entity or ADO.NET datatable all of the data in the container is being persisted with no checking if data has been modified.
It is the point I am making.
If you find the post has answered your issue, then please mark post as 'answered'.
Participant
1446 Points
2839 Posts
'Validation failed for one or more entities. See 'EntityValidationErrors' property for more detai...
May 22, 2019 07:20 AM|demoninside9|LINK
Hi All,
I am using MVC 5 with EF 6.
In my application I chose Controller with views using Entity Framwork, which automatically creates the view and methods like below.
Suppose I just guess ( not sure ) that this error comes when don't provide all fields in Edit ActionResult.
Actually I don't need to update all fields as mentioned here (bigid,vcname,vcrate_phour,dateadded,datemodi,addedby,updatedby).
I just need to only 4 fields. 2 are I am mentioning here in code.
And other two it took from like below
Please suggest.
Thanks
Contributor
4973 Points
4262 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 22, 2019 07:42 AM|DA924|LINK
You have two ways to display the validation errors.
https://www.c-sharpcorner.com/UploadFile/97fc7a/validation-failed-for-one-or-more-entities-mvcentity-frame/
https://mattrandle.me/viewing-entityvalidationerrors-in-visual-studio/
To me, it's a drawback in letting Mr. Wizard do things instead rolling your own code.
Contributor
3710 Points
1431 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 23, 2019 08:33 AM|Yuki Tao|LINK
Hi demoninside9,
According to your error message,This may be caused by restrictions or constraints in your model.
You could use try..catch..or check Quick Watch window in controller to look for the cause.
For example:
More details,you could refer to:
https://stackoverflow.com/questions/7795300/validation-failed-for-one-or-more-entities-see-entityvalidationerrors-propert
Best Regards.
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Participant
1446 Points
2839 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 23, 2019 09:23 AM|demoninside9|LINK
I already did this.
As I see the The Author_id field is required.
This is the main drawback of EF, if you want to update only few fields you have to update all fields in database table. (When you use Controller with view and entity framework).
I am looking for the solution that any fields don't have any compulsion. Fields should be free and independent for any (CRUD) operations.
any way Thanks
Contributor
4973 Points
4262 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 23, 2019 01:12 PM|DA924|LINK
This is the main drawback of EF, if you want to update only few fields you have to update all fields in database table. (When you use Controller with view and entity framework).
All ORM(s) work in the same manner when it comes to taking a persistence object and persisting it to the database table, which it's either all or nothing.
I am looking for the solution that any fields don't have any compulsion. Fields should be free and independent for any (CRUD) operations.
You can't do it with using a ADO.NET datatable either
The only way you could do such a thing would be able to develop a persistence object that kept its state, and it also kept all the properties states within the object for when logic you wrote to know when the persistence object was in a dirty state and what properties in the object were in a dirty state in order to formulate dynamic T-SQL based on the persistence object's state and the state of properties within the persistence object.
All-Star
53661 Points
24019 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 23, 2019 01:38 PM|mgebhard|LINK
You are assuming how EF works rather than taking the time to understand how it works. Anyway, the solution (programming pattern) was covered in your threads from yesterday.
Contributor
3710 Points
1431 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 24, 2019 02:27 AM|Yuki Tao|LINK
Hi demoninside9,
No,EF will not be so rigid.There are definitely other ways to implement your function.
According to your previous post,
I suggest you could use TryUpdateModel,because the Bind attribute clears out any pre-existing data in fields not listed in the Include parameter.
More details about Bind,TryUpdateModel and so on,you could refer to:
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application#update-httppost-edit-method
Best Regards.
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Participant
1446 Points
2839 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 24, 2019 03:21 AM|demoninside9|LINK
I did by using ADO.NET
Please have a look.
Below is my DataAccessLayer
Below is my ActionResult in controller.
Below is my Store Procedure
But I did not understand why you said that with ADO.Net it can not be done. May be you are trying to say something else or might be possible I misunderstood.
Contributor
4973 Points
4262 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 24, 2019 08:36 AM|DA924|LINK
But I did not understand why you said that with ADO.Net it can not be done. May be you are trying to say something else or might be possible I misunderstood.
I don't see an ADO.NET tableadapter or a dataadapter along with a dataset and datatable being used in your code, which the 'all or nothing' statement would apply for data persistent using the technology in the scenario. ADO.NET would persist the data from the datatable row and doing it column by column to the database table not concerned if the data actually changed or not for any given datatable row and column within the dataset
https://docs.microsoft.com/en-us/visualstudio/data-tools/update-data-by-using-a-tableadapter?view=vs-2019#to-update-a-database-by-using-a-tableadapter
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/populating-a-dataset-from-a-dataadapter
Participant
1446 Points
2839 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 24, 2019 09:12 AM|demoninside9|LINK
I am using dbhelper class Insert_Update_Delete (oDBHelper.Insert_Update_Delete("usp_ot_band_master_detail", param)). Which have the following methods.
Contributor
4973 Points
4262 Posts
Re: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more d...
May 24, 2019 10:02 AM|DA924|LINK
No matter how you use the ADO.NET datatable, there is sill no way that you can determine that data in a datatable row and column was modified and code is only checking for a modified column that will be persisted to a database table using an adapter, which is not unlike using an EF entity object where the persistence properties in the object are not cheeked as to what property changed with T-SQL generated for only changed data in properties by the EF engine. EF doesn't care if a property in the object has changed or not The same logic is applied to a datatable and T-SQL generated by the usage of a datatable sitting inside a dataset using an adapter or a helper that is generating the T-SQL
In either case in using a data container such as an EF entity or ADO.NET datatable all of the data in the container is being persisted with no checking if data has been modified.
It is the point I am making.