Click here to Skip to main content
15,893,401 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 Updated

Entity Framework 6.0 

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...
3 Apr 2019 by #realJSOP
0) Your linq query makes no sense because EVERY day is between the first/last day of its month. Maybe you meant to compare just the month? (We can't see what the vars LastDayofMonth and FirstDayOfMonth are, but I assumed they're a datetime.) Maybe better names would be StartDate and EndDate? 1)...
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 ...
28 Jul 2014 by _Amy
I'm adding few more links in above solution:MSDN : join clause (C# Reference)[^]SQL Joins with C# LINQ[^]C# Join[^]--Amy
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.
31 May 2014 by aanbidmij
Hello everyone,I have a small program (multi user).When I run 2 sessions of my program and in session 1 I do an update of the data, I can't see the updated data in session 2. However the updated data is stored correctly in the database.When I do an insert in session 1, I see the...
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...
29 Apr 2015 by Abdul Shakoor p
I have Models "Category" & "SubCategory". CategoryID is foreign key in SubCategory Table. I need to fetch all the Category and related SubCategories and bind in an Accordion list.This is my code :
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[^]
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...
7 Nov 2014 by Adriaan Booysen
An example of a nearly complete unknown type being used accross EF, WCF and consumed client side
21 Apr 2015 by Afzaal Ahmad Zeeshan
Since you are going to use Web API, why are you confusing yourself to use native .NET framework at all?You should build a simple Android application with default WebView control added to it. Which can then target your API. Do you know much about ASP.NET Web API[^]? If not then please learn...
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 ==...
6 Feb 2015 by Ahmed Amin
Hi01. i have create an sql function in my database that take to Date params and get data from 5 tables02. after that add it to project as entity framework from database and the code generated is: [DbFunction("Dr_EmploEntities", "SelectEmployee")] public virtual...
13 Jan 2017 by ahmed_sa
I need to build web site by .net web technology asp.net mvc USING C#But i confuse What is best for build Web site Implementation by MVCUsing Entity framework(build database and create modules automatic by EF)ORImplementing web site by using Code First ?What I have...
14 May 2015 by Akalanka Kasun
I got following exception when updating data from my database tableException : System.Reflection.TargetInvocationException' occurred in EntityFramework.SqlServer.dll but was not handled in user codeHere My Code private bool updateUser(UserCategoryModel userCategory) { using...
14 May 2015 by Akalanka Kasun
using (var db = new EntityContext()) { var count=db.UserCategories.Where(a => a.UserName == userName).Count(); return count> 0; }Here when database initialize UserCategories table doesn't generate base query?
15 Jul 2015 by Alexandru Lungu
Check Stored procedure vs standard query. It should answer your question.
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 ...
24 May 2014 by Andreas Gieriet
You might check out Invent your own Dynamic LINQ parser[^]. I wrote that parser a while ago to create predicates suitable for LINQ-to-Object queries.CheersAndi
4 Jul 2018 by Andrew797
I started developing an MVC app on my laptop, which was running VS2013, and SQL server 2008 R2. I copied this project over to my desktop computer running Visual Studio 2013, SQL server 2012 Developer Edition.When I run this MVC app from my Desktop, I get the following error on the line...
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...
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...
21 Aug 2015 by Andy Lanng
Hi,I am connected to my db via LINQ to SQL dbml objects. When I search for customers I need to get several linked tables too.These include things like Payment Details, contact history, claim history etc...I use paging so my data sets won't ever be very big. I would like to get all...
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[^]
4 Mar 2015 by anilsarapati
Hi All,I am trying to use where condition inside include in an entity framework query as below.var results = _courseService.QueryCourses() .Include(x => x.Language) .Include(x => x.Versions.Where(u=>u.Overwrite==null).Select(y => y.Language)) ...
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...
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
25 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 What do you need to know about Entity Framework Data Context Entity Framework Migrations and Data seeding This article is the second
3 Mar 2015 by Arif H Shigri
This Is The Exception Em Recieving."The property 'MeterID' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection where T is a valid...
4 Mar 2016 by AshishvermaMCA
How to pass n number of parameters to Stored Procedure(SP) in Entity Framework What I have tried:I have not any idea because in EF dynamically mapping is performed.So how can pass n- number of parameters in SP
23 Aug 2015 by Avenger1
I'm using Entity Framework for my database in asp.net but when my database is on localhost it automatically add the tables and relationships but after I uploaded my database to host and I tried to use it in model.edmx it add tables without relationships.I tried to add relationships with the...
19 Apr 2014 by Barcelonista Naser
Dear All.I am trying to build a User authentication in ASP.Net MVC4 from a tutorial. I am already done with 80 % of the project but at the end i have faced with a problem. I couldn't get a clue even googling for an hour. I have a user control just like below. using System;using...
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?
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...
7 Dec 2017 by Ben Hall (failingfast.io)
How to use FakeItEasy with Entity Framework 6
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...
24 Feb 2015 by Biswabid Rath
I want to reuse an existing project code. I have all the POCO classes(replica of tables) available with me from the old project which is attached to DBCOntext also. However in my new project my DB structure is different. I am planing to replace the old POCO classes with new ones with same...
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?
17 Apr 2019 by Christian Graus
Presumably you created those views to simply access to sets of data that resolve specific problems in your domain. So, keep them.
25 Nov 2017 by Code Atom
I m facing a problem, I have API that sends a request with a list of email addresses, now what system does it check each email address from the database, if it exists then it ok we use userid else we create a new user. The problem arises when we send multiple requests with the same list of...
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 Apr 2018 by CyberMakarov007
SQL table dependency with entity framework in WPF
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...
17 May 2015 by DamithSL
you have .FirstOrDefault(); at the end of your c# statement and it will give only single item or null value as result. if you need array or list, use ToList or ToArray methods var obj= db.Database.SqlQuery("EXEC GET_GROUP_PERMIT @GID", idParam).ToList();return...
15 Dec 2015 by databaseobjectmodel
A sample infrastructure project such as erp, mrp, crm, admin panel.
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 { ...
31 May 2014 by Dave Kreskowiak
If you're creating an instance of the context and keeping it alive for the lifetime of the application, you're doing it wrong.Create a context when you need to do a query and Dispose it when you're done. This way, you don't have to "refresh" it. It'll pickup the new data when ever you do...
24 Feb 2015 by Dave Kreskowiak
OK. Weird. You do realize you won't be able to write anything back to the database, correct?If you had, in your original solution, all of the EF code in a seperate project(s), completely seperate from the application code, you wouldn't have to recreate everything in your new solution. You...
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;...
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...
14 Nov 2015 by Dave Kreskowiak
I SERIOUSLY recommend you get this book[^] and work through it. There's a ton of concepts you're missing as evidenced by your code and you're not going to learn them in a forum like this.Your code doesn't make any sense at all and your variable names need to be redone to make them meaningful...
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.
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...
13 Jan 2017 by Dave Kreskowiak
Code First is a mode that Entity Framework works in. It is something to implement a web site. Entity Framework is an Object Relational Mapping tool. It automates a lot of the work to save data model objects to a database and reconstitute them back into objects from the database.Entity...
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 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...
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.
27 Dec 2014 by deelll
If I want to retrieve a list of data and display it by using EF code first (http://msdn.microsoft.com/en-in/data/dn468673[^]) or stored procedure (http://msdn.microsoft.com/en-us/data/jj592907.aspx[^]), which of them has the shortest time to retrieve it?
1 Dec 2014 by Dexter11
I have just started with tutorials on Entity Framework(version 6) and also used it in one of my small project.There are few questions lingering in my mind...does the model in entity framework is auto updated? what if i am changing datatype for any column in database or adding new column...also...
27 Aug 2015 by Dharma M
Hello Friends,I am new to redis caching. I want to cache our entity framework(database-first) object with redis cache as a second level and need to consume it from client. Please share how can I implement this?Regards,Dharma
11 Jun 2014 by DiponRoy
Custom Seed Serializer for Entity Framework Code First C#
28 Jul 2014 by DiponRoy
How to manage Entity Framework Code First in Real Time Projects
4 Sep 2014 by Dukhabandhu Sahoo
Explore the Entity Framework Code First convention and configuration for creating primary key
3 Sep 2014 by Dukhabandhu Sahoo
The use of different Database initializer options in Entity Framework Code First
1 Oct 2014 by Dukhabandhu Sahoo
Handle optimistic concurrency using Entity Framework Code First.
12 Oct 2014 by Dukhabandhu Sahoo
Know how to exclude types from the Model in Entity Framework Code First
14 Oct 2014 by Dukhabandhu Sahoo
Learn how property is automatically mapped to column and how to manage it in entity framework code first.
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.
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
10 Jun 2020 by Enobong Adahada
Please how do I assign table name to generic DBSet base on Model? I want to create a table for every registered user, using their userId and the table name in EF6. public class ContactModel { [Key] [Required] ...
16 May 2016 by Eswara Palachooru
Hi Folks, we have application with Asp.Net 2.0 and SQL server Database and every month we save 2 lakhs transactions in one of my database table. In this table we have column with datatype as Text(where i can have huge data as string). Now i want to implement same application with...
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...
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.
8 Mar 2017 by F-ES Sitecore
Disabling lazy loading doesn't stop related data loading, it stops it being loaded on-demand, so instead it is loaded right away. You might be better using the "Include" feature to dictate what data is lazy-loaded or not on a per-case basis. It will make it explicit what is being lazy loaded...
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...
17 Jun 2015 by fairfriend
I have some models:public class RootEntity{ public int Id {get; set;} public virtual ICollection CollectionA {get; set;}}public abstract class AbstractEntity{ public int Id {get; set;}}public class DerivedEntityA : AbstractEntity{ ...
4 Mar 2016 by Frank Kerrigan
Pass raw SQL to EF[Entity Framework Raw SQL Queries[^]]
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,...
24 May 2015 by gaurav.s23
The metadata specified in the connection string could not be loadedConsider rebuilding the web project to build assemblies that maycontain metadata. The following error(s) occurred: The provider did not return a ProviderManifest instanceDo let me know if you know the solution.
24 May 2015 by gaurav.s23
1.go where you project is located(open Solution explorer. right click on solution and click on "Open Folder in file explorer")2.open EDMX file with notepad and change ProviderManifestToken="2012" to ProviderManifestToken="2008". save it3.build your solutionIts fixed.
28 Dec 2014 by George Jonsson
This part of the code will give you this problemif (john.courses == null){ john.courses.Add(stoptalk); john.courses.Add(rails); db.Persons.Add(john); db.SaveChanges();}because if john.courses == null is true, the Add operation cannot be executed as no instance of...
2 Jan 2015 by Gerhard_Louis
First time using Entity Framework 6 with WPF.I created a sample database to get familiar with WPF and Entity Framework.How do I delete a selected entity This is my codenamespace RubyTime.Pages{ public partial class Home : UserControl { private...
18 Jul 2018 by Gerry Schmitz
A table cannot have more than one "primary key". EF can only recognize one primary key; either a single value or a compound key. Anything else would be a "secondary key / index"
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[^]
25 Apr 2020 by Gerry Schmitz
You're probably missing part of the "data" story and overriding a (duplicate) "key" with the IDENTITY function you're triggering with the "Key property".
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...
13 Sep 2020 by Gerry Schmitz
...OrderBy( o => switch( o.Status ) { case "Accepted": return 1; case "Pending": return 2; ... default: return 6; } ) .ThenBy ... etc.
26 Feb 2019 by Golden Basim
i created this view to calculate the total stocks of every item in every store as : CREATE OR REPLACE VIEW `view_items_stocks_smallest_unit_prices_noserials` as SELECT items.stitems_ID, items.stitems_Status, items.stitems_Name, items.stitems_Type, ...
4 Apr 2019 by Golden Basim
hi, i have MySQL VIEW : (4 record) sDate , Count , Amount 2019-04-01, 2, 600.0000 2019-04-02, 1, 4000.0000 2019-04-03, 2, 1400.0000 2019-04-04, 1, 3500.0000 i try to show this data in Gridview using EF6 var Purchases = DB1.view_purchases_amount_per_day.Where(x => x.sDate >= FirstDayOfMonth...
15 Apr 2019 by Golden Basim
hi, i created this view : CREATE OR REPLACE VIEW `view_items_accounts_tree_with_date` as SELECT Acitems.accitem_AccID, acc.accdet_Cat, acc.accdet_AccountCode, CONCAT_WS(' - ', acc.accdet_AccountCode,...
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 "خطأ عند محاولة ملء...
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...
9 May 2020 by Golden Basim
how to insert this datetime value to DB using EF 31/12/2021 11:59:59 PM (end of the day in the year) 1- i created this field fiscal_year_end and its datatype is DATETIME. 2- now i trying to update the record with the value fiscal_year_endvar DB1...
3 Jun 2020 by Golden Basim
hi, some times (5-10%) when i try to execute EF Query this error appear : System.Exception: خطأ عند محاولة ملء مصدر البيانات. تم طرح الاستثناء التالي: Failed to connect to the database. To learn more, see the exception details. Exception...
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...
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...
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...