Saturday

Exception: System Data Entity Infrastructure DbUpdateException

Introduction

I was engaged on MVC application utilisation Entity Framework, MVC and Jquery. I hit the Save button to save corresponding values into database, however this did,'t happen fine as common, I got the special error An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code.

Error Description

An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code

Solution I

When I started operating to resolve issue, debugging deeply and found of stack trace message then I found that this issue was because of database table identity off.

Table Identity off

I simply set table Identity on and once more tried to save relevant values into database, this time it worked fine for me.
Table Identity On


Solution II

This Error A special case of sort An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code yet was not took care of in client code likewise comes when duplicte value entering in primary key so you have to cross check to conquer this mistake.

Need to Refresh Entity Framework Model After Database Change

Once you set primary key in database then when you would like to refresh your entity framework model through front end code.

Conclusion

Another superb expertise of MVC, Entity Framework, Jquery application. Every time, in each new application usually comes new problems. From these issues, we learnt another lesson each time and smoothing approach to next time. Above, I have clarified in subtle element by what method would we be able to determine issue of A special case of sort An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code. In the event that despite everything you locate the same issue, kindly keep in mind to think of me here.

Suggested Reading

Sunday

Error CS1963: An expression tree may not contain a dynamic operation

Introduction

I was working on a MVC Application (Razor Engine) using with Entity Framework. I triggered an error not able to populate entities while binding the controls with the database. I have written below detail of error as follows:

Error Description

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1963: An expression tree may not contain a dynamic operation

TempData vs ViewData vs ViewBag

Introduction

Today, I am explaining about TempData vs ViewData vs Viewbag while working in MVC. Each one of the three (TempData, ViewData, ViewBag) terms are used to pass data from controller to View. These all have differing capacity to shield data while going from Controller to View using MVC application. In my recent articles, Explained thoroughly How to send SMS using C# and How to create charts using MVC

ViewBag

  1. ViewBag is used logically to pass the data from controller to view.
  2. It is being introduced since C# 4.0 .Net Framework.
  3. ViewData is property of ControllerBase Class from .Net Framework 4.5 C# first time.
  4. ViewBag life reach is short. It just lies under current requesting.
  5. If it redirects then its value becomes null.
  6. It doesn't required to typecasting for getting data from Controller to View.
  7. ViewBag is slower than ViewData.