Click here to Skip to main content
15,886,731 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 Score

Entity Framework 6.0 

14 Dec 2014 by MarkLTX
Automatically implement INotifyPropertyChanged for every property in Entity Framework 6.0 entity classes
28 Jul 2014 by DiponRoy
How to manage Entity Framework Code First in Real Time Projects
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
28 Sep 2014 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.
31 Oct 2015 by Richard Silveira
EntityFramework.MoqHelper library to work with Entity Framework 6 and Moq libraries doing mocks of Entity Framework main methods that access database.
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.
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.
12 Oct 2014 by Dukhabandhu Sahoo
Know how to exclude types from the Model in Entity Framework Code First
29 Nov 2015 by Michael Bogaerts
What brings the 15.2 release for XAF (win) developers
11 Jun 2014 by DiponRoy
Custom Seed Serializer for Entity Framework Code First C#
17 May 2014 by RSIBrian2014
I have just started using LINQ to Entities and I am trying to create a dynamic query that will only select partial columns and/or order by different columns dynamically. My background was writing dynamic SQL strings and using the sql client classes. I much prefer writing LINQ to Entities for...
28 Jul 2014 by Shmuel Zang
See this CP article: LinQ Extended Joins[^].
21 Nov 2015 by KK Kod
Designing and Development of a simple ASP.NET Web API.
2 Nov 2021 by Herman<T>.Instance
Migrations does not apply to T-SQL rules for ALTER TABLE ALTER COLUMN
20 Apr 2015 by Sascha Lefèvre
This would get you a list of new (!) "Transmital"-objects, just like you created new objects in your posted code:private AH_ODS_DB_Entities db = new AH_ODS_DB_Entities();List rs = db.Transmitals .Where (sl => sl.Serial == 888) ...
23 Jun 2015 by F-ES Sitecore
Code first is better when you want to write code and have a database generated that reflects that code. Database first is better when you want to design the database yourself and have the code reflect that database. So if comes down to how particular you are about the database and how...
12 Oct 2015 by Andy Lanng
This answered this question:Quote: Richard Deeming at 21-Aug-15 11:20amAre you looking for the Include method[^]?Entity Framework : Loading Related Entities[^]Loading Related Entities with Entity Framework - A Beginner's Primer[^]
10 Aug 2016 by Nathan Minier
Generic AddOrUpdate for EF with composite key support
5 Oct 2017 by Thomas Nielsen - getCore
This is a bit crude and could require som nullchecking but this should work :) public class RowMapper { /* The way i read your sample is you get a datatable with columns and rows, these are to be mapped to an entity which presumably doesn't require all...
4 Apr 2019 by Richard Deeming
It looks like you've created an entity type to represent the values returned from your view, and you've set the Count column as the primary key for that type. EF uses the Identity map pattern[^]. When it tries to load the third row (Count = 2), it thinks that it has already loaded that record....
28 Jun 2023 by Graeme_Grant
I am not sure what your relation database table hierarchical setup is, so I will focus on a typical setup. The data is stored in a flat structure, usually with a pointer to a parent node. So something like this: class Data { public int Id {...
N 20 Apr 2024 by Graeme_Grant
So the issue is the uniqueness of the key. Using a dynamic object is the cause of your issue. Each object is unique. This is easy to demonstrate. Create two instances of a class with the same values, then do a comparison. You will find that they...
24 May 2014 by Maciej Los
Have a look here:Dynamic Querying with LINQ-to-Entities and Expressions[^]Use Dynamic Entity with LINQ Queries and the CrmDataContext[^]Dynamic LINQ Queries with Expression Trees[^]Dynamic Queries in Entity Framework using Expression Trees[^]I have no idea does it meet your needs,...
31 May 2014 by Raul Iloc
You could refresh only the needed data set by using:this.MyObjectContext.Refresh(RefreshMode.StoreWins, this.MyObjectContext.MyObjectSet);But I recommend to use the advises from Solution1 and to use the method above only when you realy need it!
3 Jun 2014 by Lakhan Aanjana
Hello, I am getting this error The best overloaded method match for 'System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction(string, params System.Data.Entity.Core.Objects.ObjectParameter[])' has some invalid...
4 Jun 2014 by Sampath Lokuge
Please check this link.May be helped to you.Good Luck ! :)The best overloaded method match for
28 Jul 2014 by Richard Deeming
How about something like this:IDictionary result = context.A .GroupBy(a => a.AId, (AId, list) => new { AId, TrueCount = list.Count(i => i.Bit), FalseCount = list.Count(i => !i.Bit) }) .ToDictionary(x => x.AId, x => x.TrueCount -...
15 Sep 2014 by Bastien Vandamme
I have a solution with 3 projects. - one for Entity framework that contains my edmx diagram (App.Config) - one for my core business (App.Config) - and one for my web API (Web.Config)When I publish my project on my hosting service or my personal server I also...
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...
23 Oct 2014 by Maciej Los
Please, read my comment to the question.Have a look here: Solution to: "The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable"[^]
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 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...
3 Jan 2015 by OriginalGriff
Um...I don;t think it will help, you will always fail the test.If s.EmployeeID is an integer, then even if you convert it to a string:employeeToDelete = ctx.Employees.Where(s => s.EmployeeID.ToString() == "EmployeeID").FirstOrDefault();it will never match the string "EmployeeID", because it...
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,...
3 Mar 2015 by Dave Kreskowiak
It appears that your class should look like this:public class DomesticQuater { public int ID { get; set; } public Int64 QuaterNo { get; set; } public String QuaterType { get; set; } public int Block { get; set; } public String Area { get; set;...
4 Mar 2015 by Richard Deeming
That's not currently supported. There's a request to add this[^] over on the CodePlex site, but it dates back to 2013. The discussion suggests a few possible workarounds.
4 Mar 2015 by Richard Deeming
The result of calling:db.Books.Select(a => new { a.Title,a.Author})is an IEnumerable. There is no built-in conversion operator to turn that into a DataSet.Fortunately, it's not too hard to write one yourself:using System;using System.Collections.Generic;using...
20 Apr 2015 by Sinisa Hajnal
There is a tutorial that does exactly what you describe[^]It was a first link on google for "show datatable data in mvc".
22 Apr 2015 by Abhinav S
You can use tinyint[^] or char[^] to store 0 and 1. An alternate could also be to use a bit[^] type.Here are some examples on create a dropdownlist in a view - DropDownList / Basic usage [^]DropDownListFor with ASP.NET MVC[^]
28 May 2015 by Andy Lanng
A1: I don't know what "longer lifetime" meansA2: Entity framework is thread safeA3: Use transaction scope*B1: Only when you use itB2: Use transaction scope*B3: Use transaction scope carefully*Entity framework is thread safe. avoid using the same instance of the DBConext to...
15 Jun 2015 by Nathan Minier
This is because you have some issues in your models.Firstly, I think you have a fundamental issue with your data model. If bracelets and Guests are 1-1, that infers that a guest can never change bracelets, which is bad design and will bite you later, should a guest need to replace their...
23 Jun 2015 by Andy Lanng
For Larger projects that depend on an efficient db design:(this is 90% of the dbs I have written)I recommend pen and paper :SThe process good of DB design goes through several iterations of normalization and de-normalization. I find it useful to organize my db way before I start...
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...
19 Sep 2018 by AbhishekDotNet
Hi,I have a created two separate C# web application using EF6 (one with Database First and other with Code First approach). everything is going on smoothly but after sometime it is required to merge both.After merging , Database is same for Code First Approach.Initial I was using...
10 May 2016 by Dave Kreskowiak
Temporal tables are not supported by EF6 and is not in EF Core 1.0 (what was EF7) since EF Core 1 is a complete rewrite from the ground up to make it platform independent. It is a current feature request and is being evaluated, though don't hold out for it to show up any time soon.
16 May 2016 by F-ES Sitecore
Google "entity framework vs ado.net" to see the pros and cons of both and decide which one meets your requirements. If raw speed is a factor you may err toward ado.net, but if your code is more complex you might prefer the simplicity of EF.
27 Nov 2016 by Dave Kreskowiak
Your code is essentially single threaded. You've got 2 threads, but one is completely blocked waiting on the other. In any case, putting the LoadData code on a background thread, since it's the only thing you're doing, is no different than if you completely skipped all the Task/async/await...
9 Mar 2017 by Richard Deeming
I suspect that this is because you're using self-referencing navigation properties, and loading the entire set into memory.I can't find the equivalent documentation for EF6, but the EF Core documentation has a note that would explain this behaviour:Loading Related Data | Microsoft...
19 Sep 2017 by SlavaUtesinov
Practical guidance how to use Effort library in your unit tests including workaround with views and triggers and some pitfalls
3 Oct 2018 by #realJSOP
If it doesn't have to be a real-time process, you could create an SSIS package to import the uploaded file, create a SQL server job to run the package, schedule that job to run every N minutes, and simply let the user hit refresh on the web site whenever he wants. I know it sounds like a lot of...
15 Apr 2019 by Maciej Los
Please, refer this: Use Stored Procedure in Entity Framework[^] The most important thing is that, that you need to set "Import selected stored procedure into entity model" to create complex type and return all fields as a result. Note, that "Balance" field is calculated on "Debit" and...
2 May 2019 by Dave Kreskowiak
You can't really improve the performance using plain vanilla EF. No matter what you do, EF is always going to do one INSERT at a time for each item you're adding. There's no way to speed that up. I would suggest stepping outside EF for this and using the SqlBulkCopy[^] class instead. You're...
13 Aug 2019 by Richard Deeming
The only way to change the order of the columns is to recreate the table. But it's really not worth it - the order of the columns in the table doesn't make any difference to performance, or to the behaviour of Entity Framework. The only time it would make any difference would be if you issued a...
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[^]
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...
10 Jun 2020 by Richard Deeming
That's a terrible idea! Create a single table for your contacts, and add a foreign key relationship with the users table. public class User { [Key] public Guid Id { get; set; } public virtual IList Contacts { get; set;...
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...
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 2014 by SRS(The Coder)
Even you have to do function import for the stored procedure as well and create a new complex type to get the desired data. Please go through this blog post written by me for steps to achieve what you want :-Using stored procedures in Entity Framework Model First Approach (Part I - Adding...
19 May 2014 by Phanindra Baddula
Hai u should select Complex type why because return type is Table , or Else var Query = from Wi in objShortcutDAO.Table1 join Wt in objSettings.Table2 on Wi.WorkTypeID equals Wt.WorkTypeID join t in objSettings.Table3 on Wi.TradeID...
31 May 2014 by DamithSL
you can use Refresh method of the context or dispose the old context and create again. But if you need to refresh only when the context change and it need to be happen automatically whenever database changed. Then you can try below article with SQL Server Service Broker.AutoRefresh Entity...
1 Jun 2014 by MOjtaba Hajivandian
Hi everybodyHow can i force EntityFramework to contain local entity in my query ?for example i want to get stock of products in current invoice and current invoice contain some records that this records so must come in stock query result.
23 Jun 2014 by ponnapureddy
I created on database context from existing database by using EF Power tools. I want to add/update entity classes whenever schema changes are done. I am unable to add/update classes as per schema changes. Anybody suggest me to implement the scenario.Thanks in Advance..
4 Aug 2014 by Kumarbs
I am working on Web API controllers with EF. When i use a single table like following code am getting the JSON object correctly.static IEnumerable SelectTop5ProductsIdAndName() { NorthwindEntities northwindEntities = new NorthwindEntities(); string...
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 PrakashCs.net
Please refer site http://www.entityframeworktutorial.net/[^]it has various examples that you need.
28 Jun 2014 by Ahmad_kelany
Hello everyone,Short Story : UP2Entities up2ent = new UP2Entities();List items = new List(); items = up2ent.ViewAllItems.ToList(); lstYesTag = pnlTags.Children.OfType().Where(l1 => ((SolidColorBrush)l1.Background).Color ==...
25 Jun 2014 by Ranjeet Patel
link for this type of same problem [^]
3 Jul 2014 by Pravuprasad
Please go through below...
3 Jul 2014 by johannesnestler
So the question seems to be how to completly disable database creation through EntityFramework.The easiest is to disable the initializer by Setting it null for a given context type.Database.SetInitializer(null);An easy Approach could be to place this code in a static...
15 Jul 2014 by Member 10940041
i want to insert users information to database using entity framework. i' am using CreateUserWizard.And event of this control as follow.protected void RegisterUser_CreatedUser(object sender, EventArgs e) { Database1Entities db = new Database1Entities(); ...
28 Jul 2014 by kave2011
I have a table like belowBit AIdtrue 1false 1false 2true 2true 1false 3true 1false 3false 1true 2true 1true 3false 3true 2suppose corresponding entity for above table is A.I want a query entityframework method based that it subtract count of true from...
28 Jul 2014 by kave2011
I want to use left outer join for below tablesEntity1 in belowid A1 102 123 -24 105 56 37 38 5And Entity2id123456789101112Outputid A1 102 123 -24 105 56 37 ...
8 Aug 2014 by Uppuluri Aditya
Hi,I have two tables namely Table1 ,Table2 and two schemas Sch1,Sch2 in my database and the tables present in both the schemas.like this:Sch1.Table1(T1Col1,T1Col2)Sch1.Table2(T2Col1,T2Col2)Sch2.Table1(T1Col1,T1Col2)Sch2.Table2(T2Col1,T2Col2)i have a UI page which contains, a drop...
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.
18 Aug 2014 by Aashish vermaa
Hello,I am working on project in which we are going to use MVC 4.5 and Entity Framework6.There are some doubts in my mind that are; 1. Can we use stored Procedure with Entity framework. Because there is a scenario where we insert and update data in multiple tables on single...
19 Aug 2014 by NowYouSeeMe
1.yes..you can use stored procedure in entity frame work.but in the case of simple CRUD operations,entity method is more efficientEntity Framework CRUD Operations Using Stored Procedures[^]2.yes..you can copy that particular file only n paste in web server
19 Aug 2014 by nrgjack
1. usually i use a generic repository (search for repository pattern) you could implement a InsertOrUpdate method in your repository and make it available across every entity, you don't need to create one SP for entity.2. you can publish your files and look for the ones that have last edit...
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...
20 Aug 2014 by mymina
hi alli have a project in wpf that use Sql Server and Entity Framework Database First.And for crud in database, i'm force use stored procedure.now,for validation data:i do'nt know how to use in classes.please help me for validation property with stored procedure.
20 Aug 2014 by Xavier Nishanth
How to perform Delete operation in Entity Frame work 6?
27 Aug 2014 by Marcin1199
HiDon't ask why but I have multiple tables with the same schema (existing database, I can't change this). Then I want select in comboBox or listBox the table and then get data.Table01Table02Table03var result = context.Table01.Select(p => p);Can I somehow replace Table01 with...
27 Aug 2014 by Rajiv Gogoi
What you are trying might not be easy if not impossible. Because for entity framework, 2 different entities(and so 2 different tables) are 2 different things and are not replaceable. And why do you even want to replace it. Just to write less code ?
27 Aug 2014 by Marcin1199
IF you will have 70 databases, and inside this databases you will have multiple tables you probably ask also about possibility :)I used to use simple command, reader and I could change table or database in query. But right now because of stupidity of database creator I have a lot of work. If...
8 Sep 2014 by kave2011
I want to use GroupBy for DateTime Without (Hour and Minute and Second).I want to use only Year and Month and Day...how I use MethodBased Linq for this work.suppose My table Like below ViewDate 3/3/2012 01:03:12 1/1/2012 10:43:23 1/2/2012 09:12:12 3/3/2012...
8 Sep 2014 by Animesh Datta
Try this wayList = dbcontext.content.ToList().Where(u =>(Convert.ToDateTime(u.Date).Month==M_no) || (Convert.ToDateTime(u.Date).Year==year_no) || (Convert.ToDateTime(u.Date).Day==day_no)).ToList(); example will demonstrate the properties .System.DateTime moment = new...
8 Sep 2014 by kave2011
I solved itvar q = _db.ArticleViews.Where(m => m.ArticleId == ArticleId).GroupBy(m => new { m.ViewDate.Year,m.ViewDate.Month,m.ViewDate.Day }, (ViewDate, ArticleId1) => new { ViewDate, CountInDate = ArticleId1.Count(), });
9 Sep 2014 by Bhagyashree Chaudhari - Member 10473634
Good Afternoon ,I want to make web api , which will be in my existing " WEB FORM Application " and i want to GET , POST my data in database ( POSTGRESQL ).First , when user click on my webapi url , it will ask for client certificate if its valid (till here done ) then user can GET and POST...
14 Sep 2014 by Bastien Vandamme
I'm building a project with Entity Framework and MySQL. For compatibility reason I need to use Entity Framework 5. I did a little mistake and updated my Entity Framework to version 6.1.1 with nuget package manager. I would like to uninstall this version 6.1.1 to use the version 5. Is it possible?
14 Sep 2014 by Pheonyx
It is yesupdate-package EntityFramework -version 5I believe that is the command to install a specfici versionThis link is really useful to knowing how to use the update-package command in nuget. Nuget Update Package Command[^]
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[^]
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,...
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" })) { ...
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...
2 Nov 2014 by christhuxavier
I am going to create MVC base project with EnityFramework.But Enity Framework has three approaches as we know as,1)Schema based approach2)Model based approach3)Code first approach.which approaches is best to manipulate data for MVC project?