Click here to Skip to main content
15,893,161 members
Everything / Entity Framework / Entity Framework 6.0

Entity Framework 6.0

EF6.0

Great Reads

by MarkLTX
Automatically implement INotifyPropertyChanged for every property in Entity Framework 6.0 entity classes
by DiponRoy
How to manage Entity Framework Code First in Real Time Projects
by Emiliano Musso
In this article, we will see how to use entity framework in our Applications, developed through the various languages that Visual Studio allows us to use. The examples in this article and probably in the next, will be C # used under WinForms, but - as mentioned - this choice is not going to affect a
by Vahid_N
It's easy to forget not disposing object contexts, which leads to memory leaks and also leaves too many related connection objects not disposed as well.

Latest Articles

by Herman.Instance
Migrations does not apply to T-SQL rules for ALTER TABLE ALTER COLUMN
by Akhil Mittal
Code First Approach and Migrations in Microsoft .NET Entity Framework
by MukeshKumarTech
This article will explain how to perform CRUD (Create, Read, Update and Delete) operations in ASP.NET Core Web API using Entity Framework Core.
by Vincent Maverick Durano
This article is part 1 of the series for building a simple web application in ASP.NET MVC 5.

All Articles

Sort by Title

Entity Framework 6.0 

29 Nov 2015 by Michael Bogaerts
What brings the 15.2 release for XAF (win) developers
26 Feb 2016 by Luis Oliveira 1966
How to perform CRUD operations (Entity Framework) in dialogues (jQuery UI) and process validation in my MVC application ?My problem is related to jQuery, specifically on how to show the dialog then treat the responses/data validations from the Controller.I have this code in...
3 Jun 2015 by Grant Weatherston
I have a DataTable object, that i'm using to represent data in a view. The view is generic and therefore i want to just pass in data and display it on the page for all my models (rather than having a different view for each model, when all going to look the same visually).My problem is, i'm...
2 Dec 2021 by 4L4K1
according to the code in what I have tried section BuySellHouse is parent EstateImages is child I tried to create a 1 to 0/1 relationship. I am not sure I did it correctly inserting parent with child by code like this gives me an error ...
3 Dec 2021 by Richard Deeming
You've created both a one-to-one relationship (by convention) and two one-to-many relationships (by configuration). That's definitely not correct. Based on your description, you need: public class BuySellHouse { public int Id { get; set; } ...
14 Dec 2014 by MarkLTX
Automatically implement INotifyPropertyChanged for every property in Entity Framework 6.0 entity classes
25 Jul 2016 by m.kolbadi
The problem is that the connection string was incorrect. It wasn't immediately obviously with that error message but when you think about it, it makes sense.My connection string was:...
12 Oct 2014 by slSoftware
Hi All,I'm going to develop my application using Database first approach, is there anyway to do with layered architecture?Thanks
12 Oct 2014 by Suraj Sahoo | Coding Passion
Yes oviously there is, you can follow repository pattern for this.The best thing is to put the .Edmx file in the Infrastructure folder rather than in the core folder. Please follow the following link for Onion ArchitectureOnion Architectur[^]This is very nice and layered architecture to...
14 Oct 2014 by Suraj Sahoo | Coding Passion
Kendo and Knockout[^]Please check hereI have never used but still please check here. I will explore more from now. You can keep posting your queries below this for more discussion.Thanks :)Have you checked this??Check this[^]
20 Jun 2016 by Toan Manh Nguyen
In this article you will learn about ASP.NET Core RC2 using WEB API and AngularJS.
20 Jun 2016 by Toan Manh Nguyen
In this article, you will learn about ASP.NET Core RC2 using WEB API and AngularJS.
3 Jul 2018 by Vincent Maverick Durano
This article is part 1 of the series for building a simple web application in ASP.NET MVC 5.
6 Aug 2016 by Vincent Maverick Durano
This article explains how to create a Login page and create a custom role-based page authorization in ASP.NET MVC 5 application.
5 Aug 2016 by Vincent Maverick Durano
This is part four of the series on Building Web Applications in ASP.NET MVC 5.
19 Aug 2014 by Terence van Schalkwyk
I have been searching for an answer on the web for this and cant seem to find one, not sure if I am wording my search incorrectly or not.If I have a contact table:FirstName | LastName | OwnerOwner links to the ASP Identity tableHow when my user logs in will can I make it that it...
29 Aug 2017 by Janine_A
I have an mvc5 application that is connected to a EF database. Some fields in this database are meant to be autogenerated as declared in SQL, but when used in MVC and upon inserting records, the GUID only contains the value of 0 for all records. How can I resolve this? Any help will be...
24 Apr 2017 by SlavaUtesinov
Implementation of "insert" repository with dynamic database table (re)creation, if it not exists. It is possible to specify which migrations will be used for that otherwise will be used default creation logic. Usage example - dynamic logging and archivation or manual table creation for some purposes
7 Dec 2016 by Kuv Patel
Convert a class library of POCO classes to datacontracts for use with WCF without having to write DataContract and DataMember attributes directly to the POCO classes.
10 Nov 2016 by MammadovAdil
Automatically define state of entity graph for EntityFramework Code-First using a single line of code.
29 Oct 2014 by Mohsin Azam
as title says how can i populate a Textbox on the basis of the value of another one,first textbox is txtTasks now i want to populate project(s) which is related to that tasks in second textbox..here is the code of linq for both,but remember i am using database not pre-list for it in asp.net...
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.
22 Nov 2014 by vedatg1980
In our project we are using-Entity Framework - Repository Pattern + Unit of Work Pattern together + We are using Devexpress controls.The related part of the code for initializing our grid is:UOW = new RepositoryObject.Core.UnitOfWork();repXtraGridAddXtraEditor = new...
20 Feb 2015 by i_syed2000
I'm planning to use EntityFramework as my back end layer. I have also defined a ServiceLayer (not WCF), which has method which closely mimics application use cases.I'm trying to figure out the role of Business Logic Layer, and DAL layers and how Service layer interacts with them. Take this...
4 Mar 2015 by MatthewThomas
In this article, we'll build an ASP.Net MVC 5 web app which will search your Yammer feed for a hashtag, and display the poster's home town on a Bing map
3 May 2018 by Måns Tånneryd
Extending the entity framework with bulk operations for both inserts and updates
3 May 2018 by Måns Tånneryd
How to extend the Entity Framework with bulk insert functionality, using DbContext
15 Jul 2015 by Sabi1610
Hi,I'm running this code in the Edit View and it works fine however in the Create View it generate Object reference not set to an instance of an object error for this specific line foreach(var evnt in s) I can't seen to grasp the issue.
20 Jul 2015 by Sergey Alexandrovich Kryukov
If your correctly pointed out the line where the exception is thrown, s is null. You could see what's wrong in not time if you used the debugger. Really, you cannot ask such questions each time it happens; you really need to learn to cope with such situations on your own.Not to worry. This...
6 Jun 2020 by Golden Basim
hi, i created new project C# & EF6 (Database First), but after some times i need to update the tables ( add new tables , Fields , delete Fields) What I have tried: in this time i use MySQL Query to do that , but i ask if there are any method...
6 Jun 2020 by Dave Kreskowiak
No. You can use one or other, not both in the same project. For a new project using Code First, EF will automatically create the tables for you from the DbSet entries in your DbContext implementation.
12 Sep 2020 by Member 14892534
I am looking for solution to the issue of insert new or delete of a datagrid row that is not being identified or captured by simply checking dbcontext.changetracker.haschanges status. HasChanges picks up when user modifies existing datagrid row...
12 Sep 2020 by Gerry Schmitz
Too much "coupling". The Observable Collection doesn't interact with the data context. You add event handlers to the OC (i.e. CollectionChanged) that interact with the data context. The entities in the OC should be "detached" from the DbContext...
22 Feb 2017 by Member 11748288
hi i want change Property Name in EF Entity to create Custome XML with Web Api.my entity ispublic partial class foo{ public int ID{get;set;} public string Name{get; set;} public string LastName{get; set;}}and created Xml is Ali ...
22 Feb 2017 by Valery Possoz
Hello,You just need to decorate your class. [DataContract(Namespace = "")] public partial class foo { [DataMember(Name = "code")] public int ID { get; set; } [DataMember(Name = "Firstname")] public string Name { get; set; } ...
22 Feb 2017 by Graeme_Grant
I hear that you don't want to decorate your classes with attributes but to do it totally POCO, there is a bit more work involved. Check out Sam's Flickr.Net Lib. Here is how he does it with his Photo Class: flickr-net/Photo.cs at master · samjudson/flickr-net · GitHub[^]. My preference...
8 Nov 2019 by Golden Basim
i try to fetch the data (funds data) and filter the results with its balance but this error appear : System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.' at foreach (account_funds f in account_Funds) What I have tried: public...
7 Nov 2019 by phil.o
You cannot enumerate a collection in a foreach block and modify the collection in the same block. Usually the solution is to get back to a plain old index iteration, starting from the end of the collection. In clear, changeforeach (account_funds f in account_Funds) { if...
7 Nov 2019 by F-ES Sitecore
Rather than executing account_Funds.Remove(f); keep a collection of all the items you want to remove; var toRemove = new List(); foreach (account_funds f in account_Funds) { if (trsBalance(f.accfunds_ID) == 0) { toRemove.Add(f); } } after...
8 Nov 2019 by Richard Deeming
Another option: account_Funds.RemoveAll(f => trsBalance(f.accfunds_ID) == 0); List.RemoveAll(Predicate) Method (System.Collections.Generic) | Microsoft Docs[^]
9 Dec 2014 by JOTHI KUMAR Member 10918227
hi to all, compare date if one fields name delivery date and another field name posting date. Now i want to check delivery date is greater than posting date.how to compare using mvc.What condition shall i want to use and where i write condition in controller or model or...
9 Dec 2014 by Raul Iloc
Normally you should do the validation of your two dates on the client (in the View), so in order to do that you should do the next staps:1)Define a custom validation attribute class;2)Mark you both DateTime properties from your model with this attribute;3)Update the view to use...
1 May 2017 by Roshan Choudhary
Handling data concurrency in Entity Framework 6 with Database First Approach.
1 Jul 2015 by Sabi1610
Hi,I'm creating an MVC 4, entity framework 6 in VS 2012 web express. When trying to add a scafffolded item to add a controller the item does not appear in the context menu. I have tried various solutions;Load/unload the project Add GUID to the .projChecked Nuget but...
22 Sep 2015 by Herman<T>.Instance
Hi Everyone,I am creating a WebAPI using EntityFramework 6.0For SELECTING I use a View and that data is shown in my webpage.FOR INSERTING or UPDATING I want to use a StoredProcedure. In the EDMX I have set that up, matched all the parameters.When I execute the Update of a datarow in...
16 Dec 2014 by Mohammad Dayyan
We wanna create the following code dynamically with expression:TestDatabaseEntities entities = new TestDatabaseEntities();entities.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); // to show generated tsql// We wanna create the following code dynamicallyList...
4 Sep 2014 by Dukhabandhu Sahoo
Explore the Entity Framework Code First convention and configuration for creating primary key
2 May 2019 by OvrLrdFregus
Hey all, I am having an issue with Code first on EF6. I get this error when trying to create a migration "The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical." Here is the code: public class TradeJournal { [Key,...
27 Apr 2019 by Gerry Schmitz
You have a one-to-one relationship according to you classes. Entity Framework – mapping references with composite keys | Feb dev[^] c# - Entity Framework Code First One to One relationship on composite key - Stack Overflow[^]
11 Sep 2018 by MukeshKumarTech
This article will explain how to perform CRUD (Create, Read, Update and Delete) operations in ASP.NET Core Web API using Entity Framework Core.
27 Jan 2015 by TalentTuner
In this article, I’ll describe how to perform basic CRUD operations using code first in an MVC5 application.
11 Jun 2014 by DiponRoy
Custom Seed Serializer for Entity Framework Code First C#
12 Aug 2014 by meysam_25
hii have two classusing System;using System.Collections.Generic;using System.ComponentModel.DataAnnotations;using System.ComponentModel.DataAnnotations.Schema;using System.Linq;using System.Web;using Cor;namespace IVF_EHR.Models{ public class FileExtrainformation...
12 Aug 2014 by Nathan Minier
Your POCO is setup wrong for a proper FK relationship. You'll need to reformat some of it like so: public long? ExtrainformationABOFemaleID { get; set; } [ForeignKey("ExtrainformationABOFemaleID")]should be [ForeignKey("ExtraInformationFemale")] public long?...
12 Aug 2014 by meysam_25
no one never helped me .i am my own .ok i will figure out.
15 Apr 2019 by Golden Basim
i try to show xtrareport , this report was binding to SP using Framework, but this error appear during creating document . report.CreateDocument(true); DataRetrievalException: خطأ عند محاولة ملء مصدر البيانات. تم طرح الاستثناء التالي: Ambiguous match found. this line "خطأ عند محاولة ملء...
25 Oct 2014 by Member 10225052
Hi everybody, i want to delete an image after uploading, I have this for view: @using (Html.BeginForm("UploadMorePhotos", "Account", FormMethod.Post, new { enctype = "multipart/form-data" })) { ...
25 Oct 2014 by Suraj Sahoo | Coding Passion
Please check for the files that you are sending from client side to the Server side. Debug and chck i think this error is coming up because the files is null and without null checking you are trying to get files.ComtentLength. So null's property cannot be found that gives Null Exception. The...
25 Nov 2014 by Vishal Pand3y
I Have a model Lets say Customer and Products and this is one to many between Customer and Products ie one customer can have multiple products Now what is difference between public class Customer{public int Id { get; set; }public int Name{ get; set; }public ICollection...
25 Nov 2014 by Kornfeld Eliyahu Peter
ICollection is an INTERFACE, where List is a CLASS that IMPLEMENTS that specific INTERFACE!So the second option is bonded to the type 'List' where the first option can work with any type that implements the ICollection interface...
25 Nov 2014 by OriginalGriff
ICollection is an interface, List is a class.Which means that the first definition can take any class which implements the ICollection interface (which supports methods such as Add, Remove, and so forth: http://msdn.microsoft.com/en-us/library/92t2ye13(v=vs.110).aspx[^]) where List...
25 Nov 2014 by CPallini
Please note, your code wouldn't compile (you need to give a name to your ICollection or List property).In the first case, e.g.public class Customer{public int Id { get; set; }public int Name{ get; set; }public ICollection ProdColl{ get ; set ;}}You may use any of the...
6 Oct 2015 by rdamske
I am using OData/EF6 and I have coded up my ChangeInterceptors. I was wondering if I need to do something to ensure that two users do not step on each other if both happen to execute the same ChangeInterceptor at the same time. I cannot find anything either way about this.Russ
13 Jan 2015 by Member 10225052
HI everybody,I try to populate the data from database in a dropdownlist, like this: ViewModel:public class ClimbViewModel { public int Id { get; set; } [Required(ErrorMessage="You need to give it a name")] public string Name { get; set; } ...
16 Oct 2014 by GateKeeper22
I am have a problem with Dynamically generated compared to a regular lambda expression in code. Below is the code that I use to generate a dynamic lambda.Dynamic Lambdavar parameterExp = Expression.Parameter(typeof(T), "x");var propertyExp = Expression.Property(parameterExp,...
7 Sep 2016 by Emanuel Santos
In this article i will show how to create a basic application to detect and recognize faces using EmugCV.
31 Aug 2015 by pallavi Praharaj
I have an existing sql server database and want to add a new Entity Data Model which i want to point to that existing database.I want to use reverse engineer to make it 'code first' style. what is the advantage and disadvantage of this? What is the advantage and disadvantage of Database first...
31 Aug 2015 by Passion4Code
Detailed Explaination[^]The above link will clear your doubt I hope.EF Code First is very handy and shiny now a days, even in EF7 there is only Code First. But in EF5/6 which currently we are using, there are few times we do not opt for reverse engineering. My vote here would be for DB First...
24 May 2016 by Member 4274699
Hi guys, I have a project mvc asp.net perform with EF5 and had no problems when updating or bringing new tables , however I decided to use the EF6 to test the features but it turns out when I wanted to update the schema to add a new tables, EF6 does'nt add the tables , only added to the folder...
17 Aug 2018 by Herman<T>.Instance
Hi Folks, in my ODATA service I use EF6 to work with SQL Server. An EDMX is created also for the table Departments. In that table there is a TimeStamp field for Concurrency purposes. And yes I have added [Timestamp] data annotation in the code. And in the EDMX the field is FIXED for Concurrency...
17 Aug 2018 by Dave Kreskowiak
You never gave any details about your database schema as coded in EF, so this is just a guess. What you're seeing is the expected behavior. You are NOT supposed to make any changes to a column tagged [Timestamp] in EF. Timestamp fields are entirely managed by EF. They are used to manage...
2 Nov 2021 by Herman<T>.Instance
Migrations does not apply to T-SQL rules for ALTER TABLE ALTER COLUMN
13 Sep 2020 by Golden Basim
hi, my project was created using c# & entity framwork 6 i have this table (entries) that have status filed the status filed will fill with one of this values : Pending,Accepted,Rejected,Delayed,Completed i want to retrieve all the record sorted...
13 Sep 2020 by Gerry Schmitz
...OrderBy( o => switch( o.Status ) { case "Accepted": return 1; case "Pending": return 2; ... default: return 6; } ) .ThenBy ... etc.
5 Jun 2020 by Golden Basim
hi, based of my previous Question answers. and 2 day of search i decide to change my old approach that i use for setting a custom connection parameters. but i still have some issues, i preferred to create separated question because i thing it...
5 Jun 2020 by Maciej Los
I think that no one is able to help you due to the fact that EF configuration should be done in several places. I'd suggest to read official MySQL tutorials: MySQL :: MySQL Connector/NET Developer Guide :: 6.6 Tutorial: Using an Entity Framework...
16 Dec 2014 by raxhemanth
when i'am configuring data source to Objectdatasource the businessObjects are empty not showing any thing? what could be the reason and how to get rid of that.Somebody help me.Thanks in advance.
26 Jan 2015 by shiv Mohan
What are the advantages and disadvantages of Entity Framework 4.0. What are best scenarios and cases where we should use EF 4.0. Many Experts including Martin Fowler hates ORM , what's your say on this ?Do you prefer using Microsoft Enterprise Data Block over EF 4.0 ? There is lot of...
26 Jan 2015 by Zoltán Zörgő
Entity framework is evolving. So, I really don't prefere Entity Framework 4... when there is Entitty Framework 6. If one hates ORM, than he/she has a subjective attitude, which is out of any objective question. There are better and less good ORM implementations, but hating them... why?Still,...
14 Apr 2014 by Pheonyx
Hi Guys,I hope you are all well and that someone here might be able to shed some light on my issue.I have a database table with the following setup:ID [Bigint]Name [nvarchar(250)]ISOCode [nvarchar(5)]MarketType [tinyint]Using EntityFramework 6 Database first, I have added...
14 Apr 2014 by Dave Kreskowiak
The first question is why are you using "Type"? That is not a good name to use as it is a class name that is used by .NET and is going to lead to confusion in the code.I think your Type should become MarketType, and could also be the name of your Enum. public enum MarketType { ...
19 May 2019 by Ameer Adel Al-Zubaidy
Hello I am on my first EF6 project and I have couple of questions Project outlines Property (Building) have Rooms A Room have list of criteria or rating Each criteria own a set of values i.e. Property (Building) A have Room 1 Each room have bunch of values Value a 0-1...
19 May 2019 by Ameer Adel Al-Zubaidy
Right first of all sorry for the rough English, I am a mess right now the solution is as follows: Loop through the existing Main categories (Property(Building)) for Property.Count Property[i].Rooms = inProperty[i].Rooms So on and so forth for the other nested lists ...
21 Jun 2014 by Member 9773183
Hi, Want to know Best Way to Implement Entity Framework???Any Help Greatly Appreciated
21 Jun 2014 by Peter Leow
If you are looking for example of Entity Framework, check this out: Simple Sample with Entity Framework [^]
21 Jun 2014 by Snesh Prajapati
21 Jun 2014 by PrakashCs.net
Please refer site http://www.entityframeworktutorial.net/[^]it has various examples that you need.
8 Oct 2014 by Suraj Sahoo | Coding Passion
Entity Framework[^]This would help you for sure..:)
23 Sep 2015 by Arian Celina
This article is a part of a multi-post article on Entity Framework Code First for web applications: Entity Framework Code First Entities and entity relationships Entity Framework Data Context Entity Framework Migrations and Data seeding It is not very often that I see web development tutorials
6 Mar 2017 by Michael Doleman
A simple DAL with an integrated, lightweight model for database seeding from a JSON source, using the code-first method in Entity Framework.
29 Jul 2015 by stixoffire
I have a Database first EF model with simple POCO entities.I receive a new Product or collection of Products and want to do the following1: Add the new Products to the products table ( seems simple enough to do this in EF from what I read).2: Add the newly received Products to the...
29 Jul 2015 by Mr Ellipse
When possible, try to link objects in EF to each other by setting Navigation properties. After all, EF is an Object Relationship Mapper :)In order to check if a 'related' entity exists already in the database context (to maintain relationship integrity), you are going to have to do some...
10 Jun 2016 by Emiliano Musso
In this article, we will see how to use entity framework in our Applications, developed through the various languages that Visual Studio allows us to use. The examples in this article and probably in the next, will be C # used under WinForms, but - as mentioned - this choice is not going to affect a
27 Jan 2015 by Member 10837197
I have a problem using EF with oracle views , or views generally , I can easily retrieve data from views through my Entity(which has views only no tables) , but I can't insert/ update or delete any records giving me the below error : "The table/view does not have a primary key defined. The...
1 Jun 2017 by Sherjil_Ahmed
Mixing DB-First and Code First Approach for using SPs in EF-Way
27 Aug 2015 by SPASWIN
Hi,i am using db first approach in my application, i need to map the city_master_table entity results into my custom business model. i am unable to map the custom business model into city_master_table. Can anyone help me to find the solution.Table : city_master_tableColumns: City_PID,...
6 Mar 2015 by Nick R-Negative
Hi! I need to know how to fetch entities, but only with a part of properties, not the whole entity. I used to invoke DbContext.Set().QuerySql(), but it fails to construct a proper entity since it needs ALL the entity properties in an internal data reader. How to get only partial entities?
6 Mar 2015 by Dave Kreskowiak
You don't. In EF you only get the entire entity stored in the database re-hydrated in the DbContext tacker.You can use projection to get just the properties you need copied into another object, but the database is still going to return the entire entity record and the DbContext is still...
23 Jun 2015 by Member 9168963
Which is better with Entity Framework , code first or database first ?Why and when is it better? Thank you,