Click here to Skip to main content
15,892,059 members
Everything / Entity Framework / Entity Framework 5.0

Entity Framework 5.0

EF5.0

Great Reads

by S. M. Quamruzzaman Rahmani
ASP.NET team released Identity framework 2.0. The new release contain some new features like generic primary key. This article explain how to change primary key from string to integer & use it with MVC5.
by Dukhabandhu Sahoo
Know how to exclude types from the Model in Entity Framework Code First
by Tom Cook (UK)
How to asynchronously poll a database for an Entity with EntityFramework 5
by Dileep Ashok
Configure Many-To-Many Relationship and ListBox control in MVC and Entity Framework

Latest Articles

by Akhil Mittal
Code First Approach and Migrations in Microsoft .NET Entity Framework
by Sherjil_Ahmed
Mixing DB-First and Code First Approach for using SPs in EF-Way
by Wahid Bitar
Validated the unique constraints at dbContext ValidateEntity in a generic way by reading the IndexAttribute values.
by Nathan Minier
Generic AddOrUpdate for EF with composite key support

All Articles

Sort by Title

Entity Framework 5.0 

23 Oct 2015 by Asmaa Rashad
Hello ,iam working using MVC and Entity framework , I have a view that displsy data of "BloodDonors" table from database and i can filter them by their blood group value that selected by dropdownlist ,so i want after choosing specific blood group i call the controller function that filters and...
6 Jan 2016 by Member 10624821
This is my controller using System;using System.Collections.Generic;using System.Data;using System.Data.Entity;using System.Linq;using System.Web;using System.Web.Mvc;using C3CardKYC.Models;using System.Data.Entity.Validation;using System.IO;namespace...
9 Aug 2014 by Sreejesh T J Nair
I am new to Devexpress. Now i need help from anybody to go ahead. I have a gridcontrol in a windows application. The Data inside the gridcontrol is unbounded using EntityFramework. There are plenty of columns inside it. There are two columns named AmountDroppped and TransactionAmount. I need to...
9 Aug 2014 by Abhinav S
These might help - https://documentation.devexpress.com/#WindowsForms/CustomDocument1477[^]https://documentation.devexpress.com/#WPF/CustomDocument6094[^]You might also want to check DevExpress forums.
23 Aug 2014 by Sreejesh T J Nair
using DevExpress.XtraGrid.Columns;//...GridColumn columnDiff = new GridColumn();columnDiff.FieldName = "amountDiff";columnDiff.Caption = "Diff";columnDiff.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;columnDiff.UnboundExpression = "[TransactionAmount] -...
19 Sep 2014 by Aashish vermaa
Hi,I have some tables in my database and want to insert records in these tables using Entity framework in MVC 4.0.Insertion took place in this way that insertion of record in child table depends on the records in the master table.This functionality could be achieve easily by Transaction...
19 Sep 2014 by Richard Deeming
Literally the first result from Google for "Entity Framework Transaction":http://msdn.microsoft.com/en-us/data/dn456843.aspx[^]In all versions of Entity Framework, whenever you execute SaveChanges() to insert, update or delete on the database the framework will wrap that operation in a...
19 Sep 2014 by Member 10911231
Using Transactions you can solve your problmsusing System.Transactions; /Inculde this Directory and Referenceusing (TransactionScope trans = new TransactionScope()) { try { using (DBEntities en = new...
1 Jun 2014 by S. M. Quamruzzaman Rahmani
ASP.NET team released Identity framework 2.0. The new release contain some new features like generic primary key. This article explain how to change primary key from string to integer & use it with MVC5.
22 May 2014 by kannankeril
This article focuses on database first development using ASP.NET MVC. It uses the Northwind database and walks the reader through developing a CRUD application, applying annotations, custom styling and using the jQuery UI Accordion to deliver a more polished UI experience.
6 May 2014 by Eric Goedhart
5 Aug 2014 by Dileep Ashok
Asp.Net MVC-4,Entity Framework and JQGrid Demo with simple Todo List WebApplication
14 Apr 2015 by Member 10225052
Hi everyone,I am using the new ASP.NET Identity in my project. But I dont have a table: AspNetUsers, because I am using a other table: UserProfile.And for register I am using this:[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async...
30 Oct 2012 by Tom Cook (UK)
How to asynchronously poll a database for an Entity with EntityFramework 5
21 Feb 2015 by i_syed2000
Assume, I have the following entity set below.Phone(PhoneId, PhoneNumber) Person(PersonId, FirstName, LastName)Company(CompanyId, CompanyName)Broker(BrokerId, BrokerName)PersonPhone(PhoneId, PersonId, PhoneType)CompanyPhone(PhoneId, CompanyId, PhoneType)BrokerPhone(PhoneId,...
22 Feb 2015 by _Maxxx_
I think, to me, the Person controller needs to handle this.A Person needs to know about a Phone - but a Phone needs no knowledge of a Person.So your phone controller shouldn't need to know about Person at all.
9 Jul 2015 by Laurentiu LAZAR
Hi,I have the following Views hierarchy:_Layout.cshtml -> @model JobShop.Models.IndexVM -> is ok |_ @{ Html.RenderPartial("_LeftSlider", Model.AspNetUsers); } -> nothing here -> is ok |_ @RenderBody() for Home (Index) -> @model...
28 Sep 2014 by Aashish vermaa
Hi,I want add auto search feature on a CSHTML page.When a user type in the textbox then values got from database should be bind in a table on the CSHTML page.It should filter records base on the value type by the user in the textbox.It should keep filtering the records when user...
28 Sep 2014 by Tiwari Avinash
you can use jquery data tables plugnis which has an auto search,sort and paging options inbuilt.DATA TABLE PLUGIN[^]
21 Oct 2014 by vaibhavnigam383
Greetings to allI am using unit of work, repository pattern with entity framework 6 (code first approach) along with dependency injection,I have extended my repository to execute stored procedures as belowpublic List ExecuteStoreProcedure(IUnitOfWork unitofWork, string spName, params...
20 Oct 2014 by payne173
Hi Vailbhav Nigam.If u r Free then u can checkout the below linkhttp://www.remondo.net/repository-pattern-example-csharp/[^]
19 May 2015 by Naveen Kumar Tiwari
I am inserting multiple records in my table using loop. After insert first record exception Generates.ERROR:- Cannot add an entity that already exists?Below is my Code.Solved- PromoCodeForSpecificBook1 obj;foreach(var i in Model.BookDetail) { obj =...
19 May 2015 by Raul Iloc
1.In order to add new records in the database you have to create new objects in your foreach loop.2.A 2nd problem is the fact that you are reading the same booking promo code for each item and should be read only ones before the foreach.3.A 3rd optimisation could be to save all changes...
24 Aug 2016 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.And working out what you need to do...
5 Apr 2015 by Dileep Ashok
Configure Many-To-Many Relationship and ListBox control in MVC and Entity Framework
12 Mar 2013 by DeepsMann
Hello,I have a WCF service hosted on IIS 7.5 on my server. I have used Entity framework 5.0 in my service.When I call that service from my local system by adding service reference and creating client in a site, it takes approx 40 seconds to get the response. I tried calling the same...
12 Mar 2013 by Andy411
Some steps you can go to analyse your problem:1) Implement a simple test method in your WCF service, e.g.public in TestMethod(int data){ return (data + 1);}and look how long it takes to call it from your client.If it is fast enough, your next steps would be to see...
4 Jan 2013 by Mninawa
Does anyone have a solution for this?Could not load type 'System.ComponentModel.DataAnnotations.DatabaseGeneratedAttribute'Could not load type 'System.ComponentModel.DataAnnotations.DatabaseGeneratedAttribute' from assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral,...
3 Mar 2015 by Soufiane Rabhi
What you have to know about ADO.NET and Entity Framework
2 Apr 2014 by laxmi smiley
Enable-Migrations -ContextTypeName mvcSample.Models.Carti enabled migrations for cart.cs.migration folder with configuration is generatederror in updation.i tried Update-Database -configuration mvcSample.Models.Cartand error is:The project 'mvcSample' failed to build.please reply me
2 Apr 2014 by Code Help 2014
Check the below page for details:DataBase Update error in Entity framework.[^]
3 Sep 2014 by Saeedek
I have a program which is under .Net 4 which uses a database for data by using entity framework model. In the Visual Studio I run and debug the program without any problem. But after I publish my program with oneclick publish (from the build menu) and transfer it to a target machine which is...
3 Sep 2014 by kbrandwijk
I have seen some issues before with |DataDirectory| and ClickOnce deployment. See the suggestion here: http://stackoverflow.com/questions/19252480/invalid-value-for-attachdbfilename[^] to replace the |DataDirectory| during deployment.This is the code in VB.NET (from the link provided):Dim...
3 Aug 2015 by Member 11873526
I have heard and read a lot that EF is the fast way to connect and insert data into SQL table and it eliminates most of the code to connect with SQL. But we take the example of Large BFSI application where we have to have write all business logic inside the SP only. As i have read, EF directly...
4 Aug 2015 by Maciej Los
Please, read my comment to the question.The answer to your questions you'll find here: Entity Framework[^].As to your concern: MSDN wrote:With the Entity Framework, developers can work at a higher level of abstraction when they deal with data, and can create and maintain data-oriented...
4 Aug 2015 by F-ES Sitecore
You can still call SPs using Entity Framework, but if your system contains all of its logic inside SPs then I personally wouldn't bother with EF. EF is more for if you simply have a well-defined relational database and you want to query the database at a code level rather than an SP level.
8 Jan 2015 by srinivas vadepally
Hi,I have a below property in my model. public IDictionary> Privileges { get; private set; } I have googled but didn't find any solution to map Dictionary using fluent api.Does EF supports IDictionary mapping?
18 Mar 2014 by mosi98
hi i upload my website to host and database(asp.net mvc4 and entity framework5),but don't know the tables and show this error: Invalid object name 'dbo.News'.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for...
11 Nov 2015 by Member 10461673
Hi All, I have a Problem on Loading Edmx File in my Mvc Application,in this project we are using the sqlserver database, having 461 tables and 1560 store procedure whenever adding all sp's and table's in my application visual studio is restarting. Please Help me as soon as...
11 Nov 2015 by Krunal Rohit
Take a look at this article,Performance and the Entity Framework[^]Gogle[^]And it may be urgent to you but not to us. People will provide solution when they can. So remove that "as soon as possible" from your question.One more thing, have a habit about researching about your query and...
2 Jun 2013 by chrisndirangu
Hi I have this class;[Table("tblRegions")] public class Region : MasterEntity {public string Code { get; set; }public string Description { get; set; }public Region ParentRegion { get; set; }public Country Country { get; set; }public RegionType RegionType { get; set; } ...
29 Oct 2013 by gwyder
HiI want to map this SQL table, named Media, using EF 5.0 CodeFirst, through DataAnnotations or Fluent. [MediaID] INT NOT NULL PRIMARY KEY, [Name] VARCHAR(100) NOT NULL, [ArtistID] INT NOT NULL, [ReleaseDate] DATE NULL, [Rating] INT NULL, [Price] FLOAT...
24 Nov 2014 by King Fisher
I'm gonna create a new MVC Application. which is best EF Code First ? Model First? Db First ? I don't have fixed Database Design ,i may modify existing table may add new table . so which one is Suitable for my Requirement
24 Nov 2014 by DamithSL
check Code-first vs Model/Database-first[^] based on the comparison you better decide which is bes for your case.
24 Nov 2014 by Suraj Sahoo | Coding Passion
Quote:I don't have fixed Database Design ,i may modify existing table may add new table .As you say here, I anticipate you already have a database and may be you need modification in there in future. So I would suggest to opt for Database first approach. As you just need to add your database...
24 Nov 2014 by Sandeep Singh Shekhawat
Hi,The ADO.NET Entity Framework allows developers to choose any one approach among three possible approaches: Database First, Model First and Code First.Database First: It is a more data-centric design that is based on an existing database. The Entity Framework is able to generate a...
17 Oct 2013 by Member 10344046
I am using MVC3 and EF5 with Oraclevar authorizedSegmentIds = _userProfile .GetSegmentListings(Permissions.OperationalControls.Edit, Permissions.OperationalControls.View, Permissions.OperationalControls.Transfer) .Select(s => s.Id)return...
15 Mar 2013 by saeed1364
hi when write Package Manager Console enable-migrations for ef Code frist View this error :The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
15 Mar 2013 by Sandeep Mewara
Your question is not too clear. Following might help:MSDN: Code First Migrations[^](HRESULT: 0x80070057 (E_INVALIDARG)) on debug [^]Clear out the temporary framework files for your project in:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\For Windows 7, the...
25 Mar 2014 by pykos
Hello I have a problem when updating related entities. So my Document entity has a collection of Customers. When Im adding a new document I can add as many customers as I want, but when Im updating only scalar properties are updated. This is my code for updating a document...public...
25 Mar 2014 by Raul Iloc
The problem is that you are trying to update the Document object that come from your view, and this is not OK, because it just a copy of your document from your database; and also the deleting and the reassigning the customers for each document update is not OK. So in your controller class...
31 Aug 2012 by Eduard Keilholz
Hi,I have a question about Entity Framework 5. I generated this nice model from my (MS SQL Server) database, for example a table called 'User'. The table contains not nullable fields.Now in the old(er) versions of EF, objects would be generated with a static CreateEntityName function. In...
3 Apr 2014 by Alcides Melo
I want to drop some tables and create again following my models design. But the CodeFirst never do it, keeping trying to apply the changes that I did, but for some reason he can't. The Designs of models class is ok but the tables on SQL is not and thats why and want to drop and recreate again. I...
4 Apr 2014 by Er. Puneet Goel
Just Start from this : Entity-Framework-Sample-Application-for-Beginners
5 Apr 2014 by Dave Kreskowiak
Google for "entity framework 5 code first migrations" and you'll find what you're looking for.
24 Nov 2013 by John Korondy
It shouldn't be this hard! I am about to give up on EF...My model has weekly newspaper Editions. Each Edition can have many Classifieds. Each Classified can appear in one or more Editions. My models:public class Classifieds{ [Key,...
24 Nov 2013 by John Korondy
The problem was that EditionModel was not part of the context. Thank you, Slauma for pointing me in the right direction. The corrected Create Action is:...classifieds.Editions = new List();foreach (var p in EditionList){ var ed = await db.EditionModel.FindAsync(p); if (ed ==...
10 Apr 2013 by sishah10
I am using SOA architecture in my project.Client doesn't know about Entity they just know about POCO objects. As I am planning to use basic infrastructure(Service, Business Logic and Data Access Layer ) for other platforms also.Now problem I am getting is I can't maintain states of...
16 Aug 2015 by durgaprakash
While calling Stored procedures from Entity framework 6.1.3, we are getting the error below...Entity Framework EF6.1.3 - stored procedure, “The FunctionImport '>' could not be found in the container '>'.”
12 Feb 2015 by sagar wasule
Hi All,I'm learning Entity Framework, while trying out Database First Approach.I added an Entity Model to the project and created an API controller using Entity Framework. By just browsing the get method from the API controller Created I found that the data is obtained in json format which...
12 Feb 2015 by sagar wasule
Resolved this by disabling the lazy loading functionality in context class constructor as below,this.Configuration.LazyLoadingEnabled = false;
1 Jun 2017 by Sherjil_Ahmed
Mixing DB-First and Code First Approach for using SPs in EF-Way
12 Oct 2014 by Dukhabandhu Sahoo
Know how to exclude types from the Model in Entity Framework Code First
26 Jun 2015 by Manoj Deshmukh
Executing Stored Procedure that returns resultset using Entity Framework DataContext
1 Dec 2014 by Amit Kumar143
i created a wcf web service. my service uses EF5 data acceess to fetch data.i have only one function named GetAllAdminList() code: IAdminService.cs public interface IAdminService { [OperationContract] List GetAllAdminList(); }And...
10 Aug 2016 by Nathan Minier
Generic AddOrUpdate for EF with composite key support
29 Apr 2016 by Mayur V Lohite
4 Nov 2014 by Member 9511618
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user codeAdditional information: The entity type Employee is not part of the model for the current context.MY CODE:public ActionResult Details(int id) { ...
4 Nov 2014 by SRS(The Coder)
public ActionResult Details(int id) { EmployeeContext employeeContext = new EmployeeContext();Employee employee = (Employee)(from emp in employeeContext.Members where emp.EmployeeId == id select emp).FirstOrDefault() return View(employee); }Hope...
11 Jul 2014 by Nischal Bhatt
Hello! All,I have created an ASP.Net MVC 4 application for basic CRUD operations by following this article[^].After this I have implemented the Kendo UI Grid, the Edit Functionality works great but when I try to delete the row, I'm getting the following error:Quote:The parameters...
30 Jul 2014 by Sam k (Sam-k)
Your application attempts to delete an item but it cant pass the id for that item to delete. Try something like new{id=Model.ID} on the delete view. The ID depends on what you named yours in ur application.
5 Jan 2014 by shanalikhan
Hi I have created a complete code using EF code first approach .but when i try to add controller using EF i get the following error that :unable to determine principal end of a assiciationbetween the types model.person and supplier. while in the designer the realtion ship between...
5 Jan 2014 by Sampath Lokuge
Your declaration of models are wrong.Try is as below.public class Supplier { public int ID { get; set; } public virtual ICollection Items { get; set; } } public class Person { public int ID { get; set; } public string...
5 Jan 2014 by JoCodes
You have to set the Principal - Dependent associations using either Data Annotations or through fluent API. Means, if its 1:1 use Required annotation or 1 - 0..1 need Optional.Refer...
7 Jun 2015 by Member 11023812
Hi,I am finding difficulties in getting the dynamic resultset from a stored Procedure in Entity Framework 6.0.The scenario is like this:I have a stored procedure which gonna return resultset based on some condition.ALTER procedure [dbo].[testProc] @val varchar(50)as...
29 May 2014 by NaveenChidara
I'm able to create mock objects and do a update test with mocked entities successfully.But the issue is with create test. Here is my sample code.In this always my testPG is null and so the test failsbase class:public class TestContext where T : class { protected Mock...
18 May 2015 by .net bigner
namespace tableshow.Controllers{ public class TableShowController : Controller { private TableShowEntities db = new TableShowEntities(); public ActionResult show() { ViewBag.TableShowsData = db.TableShows.ToList(); return...
18 May 2015 by Vishal Pand3y
Try something Like that$('#your-select').change(function() { var Id= 'Get value if For your name'; $.ajax({ url:'url which gives you address', data:Id, success: function (result) {// here change value of address}});Public JsonResult...
8 May 2014 by ilaya muthumanickam
private List GetAllFieldValues(string p){ List field_values = new List(); string connectionString = ConfigurationManager.ConnectionStrings["SchoolContext"].ConnectionString; using (SqlConnection con = new SqlConnection(connectionString)) { ...
8 May 2014 by Prasad Avunoori
string colName=p;field_values = db.table1.Select(d=>new {d.colName}).Distinct().ToList();
23 Aug 2015 by vishalharne
Hello ,var employeeList = from b in Context.Employee select busing above code I can access all the records in Employee table.But I want to make this table generic. so for example I want to have a code which will dynamically give me records of Context.Manager, Context.Company...
23 Aug 2015 by Andy Lanng
I hope I have this correct:They way you propose to do this is not a good idea, but there are ways to achieve the same end result that are a good idea.Take a look at this://Generic Factory (Reflection)//Specify the worker and the return typeList addresses =...
24 Aug 2015 by Maciej Los
If i understand you well, you want to create generic method(s)/interface to perform CRUD operation on specific object (entity)...Well, you might be interested of CreateObjectSet[^] method, which creates a new instance of TEntity that is used to query, add, modify, and delete objects of the...
16 Apr 2014 by EduChapow
There's my Model, and i can't Edit it.The errors on my ModelState returns:var errors = ModelState.Values.SelectMany(v => v.Errors);[0] - "The Field Name is Required."[1] - "The Field Id is Required."[2] - "The Field Name is Required."public class Document { ...
16 Apr 2014 by Dave Kreskowiak
Uhhh, this may seem like a stupid response, but did you try supplying the required information it wants??It appears as though you're trying to use entity models in the place of a view model.
8 Mar 2015 by Swetaketu Majumder
The following is a partial of my DB Schema.https://drive.google.com/file/d/0Bx3eJEwRdRm5MkNDcjBoSGI1NVE/view?usp=sharingI have two lists containing parentNames and the leafNames I need. Now, I need to copy the required records from one entity's tables to a newly created entity's...
8 Aug 2014 by Member 10964391
Hello. I'm working on MVC application and I want to save Dictionary into DB I already have (generated with EF, DB first). I've didn't manage to find solutions, apparently EF doesn't support dictionary.I will use this to associate different hashing and cryptic algorithms in my app....
8 Aug 2014 by Sergey Alexandrovich Kryukov
The concept of dictionary if very close to relational model. You just need to have a table of key-value pairs, where a dictionary key could be a primary table key. If you have to store several different dictionaries in a single table, the key uniqueness can be violated. In this case, use a...
8 Aug 2014 by Member 10964391
Thanks, this helps. But is it possible to save these function delegates as value in table?
11 Feb 2014 by Wamuti
Hi all.I am creating a database which has a table called Faculty. The Faculty table has a column called FacultName (it is not the EntityKey). However, I would like to ensure that despite FacultyName not being a key attribute, a faculty name cannot be entered twice. How can I set this...
11 Feb 2014 by Kornfeld Eliyahu Peter
Read here:http://code.msdn.microsoft.com/windowsdesktop/CSASPNETUniqueConstraintInE-d357224a[^]
19 Oct 2014 by je-wo
I use the entity framework to create a database and and the data access layer. All seems to work fine, but now I do have a problem I am not able to solve. It seems I didn't understand something. If I create an entity A and an entity B I do get two classes Aset and Bset. If they do have a...
20 Nov 2014 by PrachiMhatre
I have two drop down list. That 2 are depend on each other.i.e. On selection of first drop down second drop down is filled. Now when I am inserting record in particular from this form(i.e. two drop down list and one text box control form), record gets inserted.But when I am editing that...
2 Mar 2015 by deepak690
i am using transaction scope in my project. Isolation level is IsolationLevel.ReadCommitted i Also tried IsolationLevel.RepeatableRead using (DBOperations dboperation = new DBOperations()) { GetAccountVoucherNuber(); }i am calling this method from Transaction...
16 Mar 2014 by mosi98
hithis is my tables class:the table roles: public partial class Role { public Role() { this.Users = new HashSet(); } public int RoleID { get; set; } public string RoleTitle { get; set; } public string...
16 Mar 2014 by Abhinav S
TryJoin Query using Entity FrameWork[^]Left Outer Join extension for Entity Framework[^]
12 Jul 2015 by Member 11832482
Please clarify this.....How to add a custom column into the joining table which is created automatically when there is many to many relation between two classes(entities)
17 Oct 2014 by Uwakpeter
Hello everyone,i am trying to add client side validation to input fields in mvc5 application, but it does not seem to validate, i am using database first workflow, i have created the metadata class and partial class that inherits the model class in the Model folder. Below is my...
17 Oct 2014 by sashkhdr
using data annotations are server side validations,client side validation by using jquery ,we can per form the client side validations