Click here to Skip to main content
15,887,683 members
Everything / Entity Framework

Entity Framework

entity-framework

Great Reads

by Jovan Popovic(MSFT)
Mapping properties in EF model to database columns that contain JSON
by Kenji Elzerman
Fundamentals of Entity Framework
by Akhil Mittal
Entity framework core, code first migrations and data annotations in EF Core
by Jean Carlo S. Passos
CRUD over Association Entity that maps to association tables

Latest Articles

by GabrieleTronchin
In this project, I've implemented the Transactional Outbox Pattern using EF Core.
by David_Cui
To introduce a free library to save some tedious work for writing mapping code between entities and DTOs
by Mark Pelf
Fix for adding new DB tables does not work in VS 2022, ver. 17.6.2, EF6 (Classic)
by Mark Pelf
Tutorial on EF7 – Code First approach using Command Line (CLI)

All Articles

Sort by Updated

Entity Framework 

5 Jun 2011 by #realJSOP
One advantage is that you learn how to not expect a 3rd-party library to be a magic bullet, and that no matter what you select, there will be issues to overcome.
29 Aug 2011 by #realJSOP
If you're asking this, then you probably aren't familiar with EF. That means there's going to be a learning curve. If you think that the schedule is robust enough to absorb the learning curve (including at least one project restart due to "lessons learned"), go for it. If not, avoid it.
7 Sep 2011 by #realJSOP
Is it a windows form app? ASP.Net? Something you pulled outa yer butt? You've given us NOTHING to help you.What does "still have problems" mean? EXACTLY What KIND of problems?
13 Oct 2016 by #realJSOP
My guess is that the specified stored procedure doesn't have a parameter named "@typ_table". Did you misspell the parameter name?
24 Dec 2016 by #realJSOP
I've never had performance issues with sql server that were not caused by something I've done. I don't use table valued parameters.You can either iterate the list and save the onbjects one at a time, or do like the first answer suggested, and serialize all the data into xml and pass the XML...
3 Jan 2017 by #realJSOP
The object you're passing to the method is not of or derived from type TEntity.
21 Jan 2017 by #realJSOP
How coincidental - I just wrote some SQL code that creates a calendar, based on the specified date range. It's nothing more than a stored proc and a function that you implement in your database. Simply call the stored proc, and it returns the "calendar", which includes the calendar year, month,...
23 Jan 2017 by #realJSOP
Here's the promised code. On my db server, this code lives in a Reference_Tables database. Change the USE statement to reflect your own paradigm.First, is the IsHoliday scalar function. If you don't need federal holidays, you can skip this, but if you do need this, you must add this...
5 Jan 2018 by #realJSOP
When you have a customized DbContext constructor.
16 Feb 2018 by #realJSOP
Collections in Entity Framework are exposed as DbSet collections.
8 Mar 2018 by #realJSOP
Put a try/catch block around your code so you can properly debug it. BTW, you don't need the alias "p" if you're not doing a join. I would also add a check to make sure sdr.HasRows is true before trying to access the sdr object, as well as check to make sure the desired column(s) exist within...
14 Mar 2018 by #realJSOP
look into the package manager console command update-database
2 Apr 2018 by #realJSOP
I would write a method in my dbcontext class that performed the necessary filtering, and bind the returned collection to the combo box. Of course, this would probably be pretty slow if you were filtering as the user typed something, but it's certainly doable.
11 Aug 2018 by #realJSOP
0) Allow the user to specify the column names and types. 1) Create a collection of an object that store your column names and types. Make sure you add code to prevent duplicate column names. There are several techniques you can use to black-box this code so you can hide validation complexity....
7 Sep 2018 by #realJSOP
You can configure the sheet to pull data from the database. Google is your friend. excel data connection - Google Search[^]
7 Nov 2018 by #realJSOP
A MERGE statement would do it (based on your limited - and nonsensical - example data set). MERGE table1 AS t USING table2 AS s ON (t.id = s.id) WHEN MATCHED THEN SET t.name = s.name, t.countryno = s.countryno, t.age = s.age, t.branchcode = s.branchcode WHEN NOT MATCHED INSERT...
27 Dec 2018 by #realJSOP
Write a stored procvedure that does the joins you want, and call it from entity framework. Two things you have to be concerned with, how long a query takes, and how much data it returns. EF ain't exactly the most efficient way to pull data when you're doing join/where.
4 Jan 2019 by #realJSOP
I gogled it and got over 10,000 results: The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. - Google Search[^] There appear to be several causes, and ONLY YOU can decided what the...
24 Jan 2019 by #realJSOP
So before you refresh the grid, get/retain the current cursor position, and restore that position after the refresh.
11 Feb 2019 by #realJSOP
I am starting a MVC5 app, and I want to use the identity functionality without Entity framework. Here are the specifics: 0) MVC5 (.Net 4.6n) with individual user authentication (either via a standard userid/pwd login, or with a common access card (CAC). 1) No external logins, such as facebook,...
27 Mar 2019 by #realJSOP
The easiest way - setup your own database, import the data into it (using the customer's stored procedures to acquire the data), and then write EF models to load it from YOUR database. EF will NOT be able to properly define models from datasets *returned by stored procs* that are selected from...
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)...
20 Apr 2019 by #realJSOP
Write a stored proc that adds the data to both tables, or set up a trigger.
7 May 2019 by #realJSOP
This website is blocked where I work, but look here: Shufti Pro API Source Code Samples | ProgrammableWeb[^] BTW, I did a google search to find that link. I heard that google searches were recently made free of charge, so you can do it, too...
12 May 2019 by #realJSOP
MySQL doesn't do dynamic sql like SQL server does. However, you can do prepared statements. Google "mysql prepared statement".
21 Apr 2020 by #realJSOP
"I have no prior experience" - google is your friend. "I need a guide or a link to read up" - no, really, google IS your friend.
5 Dec 2021 by #realJSOP
0) You don't need to store the "full project number" string. You can build it when you query the database to retrieve the desired data. 1) You shouldn't create a new project in the database unless certain minimal criteria have been met. This...
29 Jul 2014 by $*Developer - Vaibhav*$
Hi All,I am new for MVC application, just created one MVC application using database first approach (.edmx file).I’ve done insert, update, delete and select functionality but when we insert the new record (firstName) as blank it will throw the error because in table allow null is false,...
7 Oct 2021 by .NET- India
I have "Datatbase1.tt" file as i press "ctrl+s"(save) then i get this error "Could not find an implementation of the query pattern for source type 'int'. 'Select' not found " on "bold font text" below using (var context = new...
17 Sep 2014 by /\jmot
use.. var firstquery = from FeeCollection in context.tbl_FeeCollection select new { time=FeeCollection.Createddatetime, id= FeeCollection.StudentID ...
4 Feb 2015 by /\jmot
I can't test here the query, so i'm unable to provide the exact expression for your query.i'm giving you some ref you can solve it yourself.and,it'll be better for...
15 Nov 2017 by 1Future
Hi All, I am querying from table that contains a date and time i.e "2016-08-16 09:26:30.413" when i query using the table using c# like below i get no results .. for example; DateTime date = "2016-08-16" DateTime date2 = "2016-08-16 09:26:30.413" var getdate = context.Table.Where(x =>...
15 Oct 2017 by 855
User table: UserID (PK) UserName CompanyID (FK NOT NULL) Company table: CompanyID (PK) CompanyName entity framework model (v3.5) generated like : public class User { public string UserID; public string UserName; public Company company; } public class Company { public string...
6 Jul 2015 by 9000605667
this solution will use full when my front end is in MVC. But my Front end is Angular JS. So it will not resolve the issue. But i fix this issue by changing the access specifiers of Trip in Layover class from public to private.Thanks for your solution..
23 Oct 2015 by @CodeRelam
There is a blog on how to solve this exception http://www.admarketspace.com/Blog/Index. The source code is also available for download
6 Jan 2011 by [DK]KiloDunse
I have a gridview that uses entitydatasource (EF4) to select, update and delete.I use dropdownboxes in some columns.In the RowUpdating method, I get the selectedvalue of the dropdownbox and check the value.If the value is "0" then I set the NewValue to be Null like this: ...
6 Jan 2011 by [DK]KiloDunse
Already is: /// /// No Metadata Documentation available. /// [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)] [DataMemberAttribute()] public Nullable TestUserID { get { ...
7 Jan 2011 by [DK]KiloDunse
Found the problem.I did not bind the property too anything in the EditItemTemplate in the gridview. Therefore, the property TestUserID did not get in the gridviews "BoundFieldValues" collection.As a result, the property did not get updated by the EntityDataSource.
29 Jan 2011 by [DK]KiloDunse
Hi.When I use this select in a entitydatasource.CommandText:CommandText="SELECT it.[LiteratureID], it.[ReleaseDate], it.[Title], it.[Text], it.[ThreadID], it.[Added], (SELECT COUNT(fp.PostID) FROM ForumPosts AS fp WHERE fp.ThreadID = it.[ThreadID] AND fp.Status = 1) AS Posts FROM...
29 Jan 2011 by [DK]KiloDunse
Found a solution.Adding VALUE to the nested SELECT returned a list of Int32 insted.Binding like this, returned the value:Comments=''
8 Apr 2013 by _Amy
Try this:var listOfUsers = (from x in context.CMSPI_CODICIACCESSO join u in context.CMSPI_ANAGRAFICAINFOBASE on x.IDANAGRAFICA equals u.IDANAGRAFICA select new { RowA = x, RowB = u });DataTable result = new DataTable();foreach (var x in listOfUsers){ ...
21 Nov 2013 by _Amy
You need to add the reference of System.Data.Entity.dll in your project.--Amit
24 Jul 2014 by _Amy
Try this:@Html.TextBoxFor(m => m.MyDate, new { Value = Model.MyDate.ToString("DD:MM:YYYY")});   -Amy
26 Jul 2014 by _Amy
I would recommend you to go through the links below:Creating a DropDownList for Enums in ASP.NET MVC[^]How to simple Html.DropDownListFor MVC.NET[^]    --Amy
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
24 Aug 2014 by _Amy
Try this://Since date columns accepts null in your db table//Make it nullableDateTime ?FromDate = DateTime.Now; DateTime ?EndDate = DateTime.Now;var Transaction = (from c in context.JobCards where (c.TransDateRequired >= FromDate ...
26 Aug 2013 by _Asif_
Check thisstore procedures with ASP.NET MVC 2[^]
19 May 2014 by _Asif_
Google search returned following Extreme Optimization #1.1: Mapping IP addresses to country codes.[^]how to determine if an ip address belongs to a country[^]
2 Aug 2014 by _Asif_
In continuation of What Nirav has suggested, i would suggest to add an explicit field like [PasswordChangeDate] in the User Table as in standard design a table usually have UpdatedAt field which necessarily gets updated if there is a change in the User table. PasswordChangeField will only get...
12 Dec 2015 by _ProgProg_
Dear All,I am trying to implement localization to stringlength attribute for all models with the same way i have localized the DisplayName attribute.The only change is that i will take the new value from the core class mapped attribute not from a resource file.I am using...
12 Dec 2015 by _ProgProg_
Dear All,I want to add attributes to model class properties based on some conditionsexample:Suppose the following EmployeeModel Class:public class EmployeeModel { public int EmployeeId { get; set; } [Required] public string EmployeeName { get;...
17 Mar 2016 by _ProgProg_
Dear all,I 've a working project with entity framework but i couldn't identify EF Version.Firstly:i checked EntityFramework.dll properties in Visual studio and i found the following:Rnumtime Version: v4.0.30319Version: 6.0.0.0Actually i don't know what is the...
22 Apr 2018 by _ProgProg_
Hello dears, I have a situation as follows: I want to alter all get queries in my application to skip deleted records which is marked as deleted in DB. Can i configure the context to exclude to do that instead of altering all queries? Regards, Amr What I have tried: i have searched a lot...
20 Nov 2023 by A Belal
I get tokenKey from path https://localhost:7107/api/login And when i try to test token and get data from Path https://localhost:7107/api/Values the token work good and data comes well but when i remove token the data continue come and...
18 Dec 2023 by A Belal
in Repository Pattern System.NullReferenceException Delete Method System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=Microsoft.EntityFrameworkCore StackTrace: at...
23 Sep 2015 by A. A. J. Rodriguez
I'm updating really old VB.NET legacy code to a more testable MVP/MVVM pattern. I'm not very experienced with Entity Framework, but I'm slowly getting more and more acquainted with it. However, the following anti-pattern from our database is confounding me to no end, and I'd appreciate some...
3 Jun 2014 by A.Girish
Hello Friends,I'm interested in MVC I have one small Doubt.I want to know how to generate dynamic queries for example.If i want to retrive items 8 and brand=='Reebok' delivery=2days then what i...
17 Jul 2014 by A.R Farooqui
Mty code is :public static List GetPlansbyZipCode(string ZipCodeName) { DataTable dt; using (var Context = new ConserviceEntities ()) { var list = (from zip in Context.ZipCodes from tdsp in...
3 Oct 2012 by a_behzadi
I moved membershiptables to my database by using aspnet_regsql.exe. Then I created a table named "Article" and needed to save the user id of the article`s author in "Article" table. So I added a column with name "Author" and type uniqueidentifier in "Article" table and then created a relation...
13 Aug 2012 by A_sachin
hi,I am trying to create json enabled wcf services with entity framework 4.0.when i return the response in XML format using [WebInvoke(Method = "GET", UriTemplate = "/getStudents", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Xml, ResponseFormat =...
14 Aug 2012 by A_sachin
hi i got the solution for my problem...i just need to make some changes in web.config file for my endpoint behavior...and now it is working well...Thnks for your consideration..and in order to serialize the list() into Json i used JavaScriptSerializer public string...
23 Apr 2014 by aanbidmij
Hello everybody!First of all sorry about my bad English. I am a starting programmer and I have following problem.With EF and a generic repository I can do an Insert and Delete without any problem.The problem is invoked when I do an update on the same database and same object.The...
8 Jun 2014 by aanbidmij
I was forgotten to install sql on other pc
6 Sep 2012 by Aarti Meswania
Connection strings format as belowFor Sql authenticationData Source=MyPc\SQLEXPRESS;Initial Catalog=My_DB;uid=im;pwd=pwd;timeout=100000;For Windows authenticationData Source=MyPc\SQLEXPRESS;Initial Catalog=My_DB;Integrated Security=false;Happy Coding!:)
31 Mar 2013 by Aarti Meswania
DataGridViewComboBoxColumn dgvCmb = new DataGridViewComboBoxColumn();dgvCmb.Datasource = dt;//data tabledgvCmb.DisplayMember = "column1";//column to displaydgvCmb.ValueMember = "column2";//id columndataGridView1.Columns.Add(dgvCmb, "myName");Happy Coding!:)
29 Aug 2014 by Aashish vermaa
Hi,I need some help in the following seniors:1. I have a view page where I display around 10 records without using any filter condition. But after all the data bind on the page, user could search a particular record or filter record. How can I achieve this functionality using...
23 Sep 2014 by Aashish vermaa
Hi,I am using entity framework Transaction for inserting and updating data in multiple tables.It works fine for the small data but throw following error when data is huge:System.Data.EntityException: The underlying provider failed on Open. --->...
18 Nov 2014 by Aashish vermaa
Hi,I am using entity framework for getting the result from database with the help of the following query:var resManagerGroup = (from objManagerGroup in objEntities.LK_MANAGER_GROUP where objManagerGroup.user_id == iManagerId && objManagerGroup.group_id...
2 Jun 2014 by abbassep sep
Hi anybodyI have two Entities(Asset and Owners). the relationship between them is many to many.public class Asset { [Key] public int AssetId { get; set; } public string AssetName { get; set; } public List Owners { get; set; } }public...
12 Sep 2019 by Abdalla Ben Omran
In SQL Server named two Tables like this : 1-FXXL$Purchase Line 2- FXXL$Purchase Header when i build a Modles then Dbcontext and trying to call those Tables with different form or name because i can't leave space or write '$' it won't call and the value is always null . i tried many forms but...
16 Feb 2016 by AbdelrhmanRaafat
I want to use one of the 3 ORM options (NHibernate, EntityFramework and LinqToSql) in my application which one is the better? and what is the advantages of it over than others?
2 Sep 2015 by Abdisamad Khalif
You need to learn the following technologiesASP.NET, ASP.NET MVC, Entity Framework (with the approach you want like - Code First, Model First or Database First).To learn those technologies and more, the following links will be useful for you:-1- Introduction to ASP.NET MVC...
23 Feb 2011 by Abdul Quader Mamun
A sample ASP.NET application development using MVC.
18 Jul 2015 by Abdul Rahim Abdul Rasheed
I am having a code snippet of logic 1.there are two dbset (1)deal dbset (2)archive dbset I want to join the two lists together where condition is1. I am passing a value to the method and in query it will check list 2 for users with the particular ID, neglect them and then joins the result from...
31 May 2016 by abdul subhan mohammed
Hi guys,I'm new to windows based applications.i have created one application in which i have to upload some images andthese images should be display in a grid.In this, i'm using entity to save/fetch data.i successfully saved the images in the database, but now i want to fill it...
31 May 2016 by abdul subhan mohammed
private ImageList FetchAllImages() { ImageList imglist = new ImageList(); string qry = "Select * from tbl_ScreenImages"; SqlCommand cmd = new SqlCommand(qry, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); ...
28 Dec 2013 by Abhai Oza
using (var dbCtx = new EmployeeEntities()) { //Mark entity as modified dbCtx.Entry(stud).State = System.Data.EntityState.Modified; dbCtx.SaveChanges(); }If am set property "Entry" in Entitties then display error.So i have not any idea...
22 Jul 2016 by Abhay@Accenture
Performance tuning using SqlBulkCopy
21 Jun 2016 by Abhilask kumar
I have two model first is expense and second is Itemmodels. Store all Product in Itemmodels with id,Name and in expense store only itemId. so i need get record from both table through join code is below. But this is fetch error:LINQ to Entities does not recognize the method 'System.String...
16 Oct 2016 by Abhilask kumar
Clear dot my self. I recreate new MVC project with intranet template. And then my code working fine.
13 Oct 2015 by Abhinav Pal
How to Store Table Values In C# properties using Linq. Using GetAll() method in three tier architecture.Without using Iqueriable method.Properties are just "Get and Set" methods nothing more."I want to store my table data in "get& set" properties using Linq, and Entity Framework,and...
26 May 2011 by Abhinav S
Clog: Client Logging, Silverlight Edition[^] is an excellent article about a highly customizable client logging provider.
12 Aug 2011 by Abhinav S
Looks like you are trying to insert something into a foreign key which is not available in the primary key field of another table.
28 Aug 2011 by Abhinav S
Read more about Referential Constraints[^] in the Entity Framework.
4 Feb 2014 by Abhinav S
Turn on identity on the table at the database level.SET IDENTITY_INSERT Book ON
21 Jan 2015 by Abhinav S
If you are building a small application then it can be used.It ties in well with ASP.Net Identity Framework as well.Larger applications, maintenance makes it difficult.
26 Jan 2015 by Abhinav S
You can debug and check exactly where the error occurred and what caused it.That would be the easiest way to find the error.
21 Mar 2015 by Abhinav S
The easiest solution would be to set the ReadOnly property to true.Another approach could be to make the cell style transparent.Style = { ForeColor = Color.Transparent,SelectionForeColor = Color.Transparent }
5 Apr 2015 by Abhinav S
These links will help you learn about updating data using Entity Framework -Add, Update and Delete Objects in Entity Framework 4.0[^]How to: Add, Modify, and Delete Objects[^]Update Existing Entity using DBContext [^]
28 Apr 2015 by Abhinav S
Some examples that could help you get started -Creating Multiple Choice Exam Application Using ASP.NET MVC Framework[^]Simple Dynamic Quiz in Asp.net MVC3 Razor[^]Survey Web App Using ASP.NET MVC 4, Entity Framework 5[^]
11 Nov 2015 by Abhinav S
TryUsing MyCouch to store ASP.Net identity data in CouchDb or in the cloud using Cloudant [^]CouchDB Many To Many Joins[^]These links should help you get started.
31 Jan 2016 by Abhinav S
A user should have access to all pages in your application once they login.Thus, if you want to control access at controller (method) level and allow some users access to only some methods, then view the problem as an authorization one (not authentication).For more on authorization, try...