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

Entity Framework 5.0

EF5.0

Great Reads

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

Latest Articles

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

All Articles

Sort by Updated

Entity Framework 5.0 

6 Jan 2022 by Venkata Durga Rao
I have the following Public class Pupil{public string Name {get;set;}public string Gender {get;set;}public string Standard {get;set;}}Name Gender Standard----------------------------------phani Male FirstAbraham Male ...
1 Jun 2017 by Sherjil_Ahmed
Mixing DB-First and Code First Approach for using SPs in EF-Way
16 Mar 2017 by star_tasneem
I have a database table consists of {EmployeeId,name,city,gender}. i want to retrieve them and show it in the view..but getting the exception of "Additional information: The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the...
7 Feb 2017 by Dishant Arora
Hi,I have two tables one is product and second is tags. They have their respective columns. There is one to many relationship between product and tags. One product can have multiple tags(This has to be done using Database, no Javascript). So, I have included Product key as foreign key into...
7 Feb 2017 by Andy Lanng
It sounds like you actually have a many to many relationship. This requires a link table which contains a foreign key for both products and tags. Each product can be inserted without constraint and each 'new' tag can be inserted without constraint. when you know which tags should be hooked up...
7 Nov 2016 by Wahid Bitar
Validated the unique constraints at dbContext ValidateEntity in a generic way by reading the IndexAttribute values.
6 Sep 2016 by Umesh AP
I am developing MVC application with Searching, Paging. I have UploadDate calendar control for filter purpose with many other fields. This may be null or may contain date. How to write LINQ where clause that retrieves records whose UploadDate (column name) equals to given UploadDate on form....
6 Sep 2016 by Richard Deeming
Convert the date value in C#, before passing it to the query:DateTime uploadDate;bool haveUploadDate = !string.IsNullOrEmpty(searchByUploadDate) && DateTime.TryParse(searchByUploadDate, out uploadDate);IQueryable result = db.TestUploadData2;if (haveUploadDate){ ...
27 Aug 2016 by bubai banerjee
I am developing a asp.net MVC application.Here i want to display 15 mins time interval and one textbox displayed each time for that particular day.Example:Time Activity10.00am Go for Breakfirst10.15am return for Breakfirst10.30am Back to study10.45am write...
24 Aug 2016 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.And working out what you need to do...
10 Aug 2016 by bubai banerjee
In my MVC application,i want display result (when i enter the application no in Id textbox,it will display the customer FirstName,LastName,Address in respective textboxes instead of displaying it in webgrid,in the same page by using EF.i am using mvc4,visual studio 2012 and EF.Thanks in...
10 Aug 2016 by Member 11114915 - Tanvi
In order to display the result in respective textboxes, kindly use TextBoxFor instead of DisplayFor.PFB changes required in Details View.Details View:@model CodePrjctQues.Models.tblCustomer@{ ViewBag.Title = "Details";}Details tblCustomer ...
10 Aug 2016 by Nathan Minier
Generic AddOrUpdate for EF with composite key support
9 Aug 2016 by bubai banerjee
In my MVC application,i want display result (when i enter the application no in Id textbox,it will display the customer FirstName,LastName,Address in respective textboxesinstead of displaying in webgrid,i want to display record in the same page by using EF.i am using mvc4,visual studio...
9 Aug 2016 by Member 11114915 - Tanvi
In order to display the result in respective textboxes, kindly use TextBoxFor instead of DisplayFor.PFB changes required in Details View.Details View:@model CodePrjctQues.Models.tblCustomer@{ ViewBag.Title = "Details";}Details tblCustomer ...
29 Apr 2016 by Mayur V Lohite
21 Apr 2016 by mayank.bhuvnesh
HiI am trying to connect to database server using IP in MVC Entity Framework but I get the below error while connecting.Error: System.Data.SqlClient.SqlException: Invalid object name 'Login'.Please provide the solution for the same.What I have tried:Connection...
21 Apr 2016 by Praveen_Kumar Gupta
This usually simply means a configuration issue; 1. perhaps there genuinely is no such table 2. perhaps the table is there, but isn't the the dbo scheme (it might be in Fred.Categories) 3. perhaps the db is case-sensitive (which is fine), and the table is actually...
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
4 Mar 2016 by Frank Kerrigan
Pass raw SQL to EF[Entity Framework Raw SQL Queries[^]]
6 Jan 2016 by Member 10624821
This is my controller using System;using System.Collections.Generic;using System.Data;using System.Data.Entity;using System.Linq;using System.Web;using System.Web.Mvc;using C3CardKYC.Models;using System.Data.Entity.Validation;using System.IO;namespace...
15 Nov 2015 by Rahul Pawar LogicMonk
Simple Demo Entity Framework - a tutorial explaining Code First!
11 Nov 2015 by İlker Eker
While using EF you should use tables with a primary key. And while importing views, view should use the Primary key itself.
11 Nov 2015 by Krunal Rohit
Take a look at this article,Performance and the Entity Framework[^]Gogle[^]And it may be urgent to you but not to us. People will provide solution when they can. So remove that "as soon as possible" from your question.One more thing, have a habit about researching about your query and...
11 Nov 2015 by Member 10461673
Hi All, I have a Problem on Loading Edmx File in my Mvc Application,in this project we are using the sqlserver database, having 461 tables and 1560 store procedure whenever adding all sp's and table's in my application visual studio is restarting. Please Help me as soon as...
23 Oct 2015 by Asmaa Rashad
Hello ,iam working using MVC and Entity framework , I have a view that displsy data of "BloodDonors" table from database and i can filter them by their blood group value that selected by dropdownlist ,so i want after choosing specific blood group i call the controller function that filters and...
24 Aug 2015 by Maciej Los
If i understand you well, you want to create generic method(s)/interface to perform CRUD operation on specific object (entity)...Well, you might be interested of CreateObjectSet[^] method, which creates a new instance of TEntity that is used to query, add, modify, and delete objects of the...
23 Aug 2015 by Andy Lanng
I hope I have this correct:They way you propose to do this is not a good idea, but there are ways to achieve the same end result that are a good idea.Take a look at this://Generic Factory (Reflection)//Specify the worker and the return typeList addresses =...
23 Aug 2015 by vishalharne
Hello ,var employeeList = from b in Context.Employee select busing above code I can access all the records in Employee table.But I want to make this table generic. so for example I want to have a code which will dynamically give me records of Context.Manager, Context.Company...
17 Aug 2015 by Thomas Nielsen - getCore
Use Open XML for instancehttps://msdn.microsoft.com/en-us/library/office/bb448854.aspx[^]Then you have a very fast and easy way of getting the dataNow as you know Entity framework is just a convenient way to wrap a database into .net object, so you design your recieving table in...
16 Aug 2015 by Rijen Juni
How to insert data from excel to sql server using Entity Framework, if you have project or any advice please tell me
16 Aug 2015 by durgaprakash
While calling Stored procedures from Entity framework 6.1.3, we are getting the error below...Entity Framework EF6.1.3 - stored procedure, “The FunctionImport '>' could not be found in the container '>'.”
4 Aug 2015 by F-ES Sitecore
You can still call SPs using Entity Framework, but if your system contains all of its logic inside SPs then I personally wouldn't bother with EF. EF is more for if you simply have a well-defined relational database and you want to query the database at a code level rather than an SP level.
4 Aug 2015 by Maciej Los
Please, read my comment to the question.The answer to your questions you'll find here: Entity Framework[^].As to your concern: MSDN wrote:With the Entity Framework, developers can work at a higher level of abstraction when they deal with data, and can create and maintain data-oriented...
3 Aug 2015 by Member 11873526
I have heard and read a lot that EF is the fast way to connect and insert data into SQL table and it eliminates most of the code to connect with SQL. But we take the example of Large BFSI application where we have to have write all business logic inside the SP only. As i have read, EF directly...
3 Aug 2015 by Member 11883599
I am new to ASP MVC and developing inventory control system. i have two main Tables(classes) Sale & SDetails as mentioned below. i want to use one single page to insert several products details and automatically calculate total. when user click issue button, all products details should be...
17 Jul 2015 by RobertRos
I use VB2015 and EF6. i have an invoiceline table with orderlines. In the invoiceline is a productID. This productID is connected with a foreign key relation to a product table. When i put the invoiceline as a datagridview on a form and the related productname in a label the name in the label...
15 Jul 2015 by spankyleo123
Thanks Guys, unfortunately none of the options worked. So had to write a SP and call it in the code, which solved the issue.Thanks again.
14 Jul 2015 by Hector Menchaca
Hello,Maybe at the moment of doing the render of your page you are not using the List class..I found this article and I think it can helps.http://stackoverflow.com/questions/27378288/but-this-dictionary-requires-a-model-item-of-type-system-collections-generic-ie[^]Best Regards!
13 Jul 2015 by lokopi.nagar
I am building a registeration form, i am having problem in which class should i bind my index view to i am having three classes Districts, Tehsil, Subtehsil, which basically implement the cascading dropdownlist in the same order.public partial class District { public District()...
12 Jul 2015 by Member 11832482
Please clarify this.....How to add a custom column into the joining table which is created automatically when there is many to many relation between two classes(entities)
9 Jul 2015 by Laurentiu LAZAR
Hi,I have the following Views hierarchy:_Layout.cshtml -> @model JobShop.Models.IndexVM -> is ok |_ @{ Html.RenderPartial("_LeftSlider", Model.AspNetUsers); } -> nothing here -> is ok |_ @RenderBody() for Home (Index) -> @model...
27 Jun 2015 by Afzaal Ahmad Zeeshan
Database server (SQL Server) is a stand-alone application that doesn't have to rely on anything to provide you with data, apart from a few factors such as latency rate etc. So that is why, executing the command (SELECT) would take only 1 second. Whereas WCF on other hand has to depend on...
27 Jun 2015 by vikro
I have write a one store procedure it return 23000 records and its getting 00:00:01 Sec. Timing in Sql-Server ,but when i call this store procedure using WCF + Entity Framework its require timing is 10 Sec (in local Network) for getting result from database So how to decrease WCF Service...
26 Jun 2015 by Manoj Deshmukh
Executing Stored Procedure that returns resultset using Entity Framework DataContext
21 Jun 2015 by Maciej Los
Have a look here: How to: Combine Data with LINQ by Using Joins (Visual Basic)[^]I'd do that this way:Dim query = (From f In foo Group Join b In bar.Where(Function(x) x.Pid = 10 And x.Sid=20) On b.Id Equals f.Id Into g = Group From fb In g.DefaultIfEmpty() ...
18 Jun 2015 by deepankarbhatnagar
Hi, try this,from f in foo join b in bar on f equals b.Id into bs from b in bs.DefaultIfEmpty() where b.Pid = 10 and b.Sid = 20 select new { Name = f.Name, Id= f.id == null ? "Null" : f.id};Thanks in advance
18 Jun 2015 by spankyleo123
Hi Guys, I am basically trying to write the following SQL query in Linq to Entities using vb.net. select * from foo fleft outer join bar bon b.Id = f.Id and b.Pid = 10 and b.Sid = 20My linq query is as followsDim query = (from f in foo group join b in bar...
17 Jun 2015 by gunkrr
I'm using Entity Framework 4.1When i update entity (has child table with 50 data), it will be long timeCause of EF will send 50 delete query and 50 insert query to child tablethe example code is below : var existingEntity = (from E in Entities.Include("GoodReceiptItems") ...
14 Jun 2015 by Member 9437509
Hi frends,How to handle primay key,1. if u added a new column in primary key[compisote key],how this get affected in edms/code.2.if a new column modification happend in db, how to handle in ef, codeplease help learn in this.
7 Jun 2015 by Member 11023812
Hi,I am finding difficulties in getting the dynamic resultset from a stored Procedure in Entity Framework 6.0.The scenario is like this:I have a stored procedure which gonna return resultset based on some condition.ALTER procedure [dbo].[testProc] @val varchar(50)as...
20 May 2015 by Peter Leow
First thing first,1. There is no need for Name field in the employeestatus table as it rightfully belongs to employee table, this concerns http://www.studytonight.com/dbms/database-normalization.php[^] 2. Avoid using 'date' as field name as this is a reserved word in sql and it should be...
20 May 2015 by Sajid227
i have a dropdown list for the a number of functions like wedding,birthday etc,and three are two table Employee,AND EmployeeStatus TableEmployee Tableid Emp_Id Name 1 23 ssss2 24 dddd3 34 ffffand EmployeeStatus Tableid ...
19 May 2015 by Raul Iloc
1.In order to add new records in the database you have to create new objects in your foreach loop.2.A 2nd problem is the fact that you are reading the same booking promo code for each item and should be read only ones before the foreach.3.A 3rd optimisation could be to save all changes...
19 May 2015 by Naveen Kumar Tiwari
I am inserting multiple records in my table using loop. After insert first record exception Generates.ERROR:- Cannot add an entity that already exists?Below is my Code.Solved- PromoCodeForSpecificBook1 obj;foreach(var i in Model.BookDetail) { obj =...
18 May 2015 by Vishal Pand3y
Try something Like that$('#your-select').change(function() { var Id= 'Get value if For your name'; $.ajax({ url:'url which gives you address', data:Id, success: function (result) {// here change value of address}});Public JsonResult...
18 May 2015 by .net bigner
namespace tableshow.Controllers{ public class TableShowController : Controller { private TableShowEntities db = new TableShowEntities(); public ActionResult show() { ViewBag.TableShowsData = db.TableShows.ToList(); return...
4 May 2015 by Sanchit Jain
I am new in Entity framework. Please help me to convert these sql query in Entity Framework. Here table name is DB_Deals and Title, ProductDescription,VendorName are the fields.Here is the Query:-1.SELECT DISTINCT Title, ProductDescription, COUNT(1) as Duplicate FROM DB_Deals GROUP BY...
30 Apr 2015 by Tomas Takac
Solution #3 is basically correct. You need to create and Expression on the fly. EF examines the expression to generate the SQL so plain lambda won't work. Here is my approach:static Expression> CreateExpression(string propertyName){ var type = typeof(T); var...
30 Apr 2015 by Sascha Lefèvre
This is basically the same solution as solution 3, but a bit beautified.Required "usings":using System;using System.Linq;using System.Linq.Expressions;Extension class:public static class QueryableExtensions{ public enum Order { Asc, Desc ...
30 Apr 2015 by Venkata Durga Rao
public static IQueryable OrderByDynamic(this IQueryable query, string sortColumn, bool descending){ // Dynamically creates a call like this: query.OrderBy(p => p.SortColumn) var parameter = Expression.Parameter(typeof(T), "p"); string command = "OrderBy"; if...
29 Apr 2015 by Karthik_Mahalingam
add System.Linq.Dynamic.cs [^] file to your solution and use the below code to do dynamic order by references : dynamic-query-library[^]static void Main(string[] args) { List list = new List(); list.Add(new Pupil() { Name = "b"...
23 Apr 2015 by Pascal Ganaye
You say "when data in that table will increase then it will consume more time"This is not necessarily as bad as you think.It really depends of the Linq provider.Let me explain.When you execute this query, the engine is not going to run it sequentially in this order: 1 -...
23 Apr 2015 by pankajrawat
I will always suggest, use group by and order by in last
23 Apr 2015 by Sajid227
i have a query that is full filling my requirement ,but problem is that when data in that table will increase then it will consume more time ,i want to alternate query in EF so that i will not get that chance. my query is as follow: var ranks =...
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[^]
22 Apr 2015 by Member 11579819
I want to add a drop-down to one of my view on MVC and it should send either 0 or 1 to database. What data-type should i select in database so as to make it to accept only 0 or 1. And most importantly how to create that drop-down on my view. Please help!!!
22 Apr 2015 by Sergey Alexandrovich Kryukov
You cannot just "get" event confirmation. This is not how it works. If the server hosting e-mail of the addressee implements this feature and if it is enabled by their local policy, you will receive response (with some receipt) via e-mail at the sender's address. For further detail in requesting...
22 Apr 2015 by Member 10225052
Hi,I am trying to implement the register method with email confirmation, like this: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task Register(RegisterModel model) { if (ModelState.IsValid) ...
20 Apr 2015 by Member 10225052
Hi everybody, I try to implement the function recover email. I get the email with link for recover passsword, like this: http://localhost:41787/Account/ResetPassword?rt=cgUuxE3xpVnjkQEkpif73Q2[^] , And i also see that in the datbase there isa PasswordVerificationTokenBut if I past...
16 Apr 2015 by Somu544
OPEN SYMMETRIC KEY mykey DECRYPTION BY PASSWORD = N'xyz+'; select CONVERT(varchar(15),DecryptByKey(empname)) from emptableThis is how we retrive using sql. How to do the same thing with entity framework using lambda expressions
14 Apr 2015 by Member 10225052
Hi everyone,I am using the new ASP.NET Identity in my project. But I dont have a table: AspNetUsers, because I am using a other table: UserProfile.And for register I am using this:[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async...
9 Apr 2015 by Omar Al Zabir
An example Web application showcasing the amazing features of ASP.NET MVC, WebAPI, EF together with ESB to build a secure, reliable, REST based web api, and web frontend.
5 Apr 2015 by Dileep Ashok
Configure Many-To-Many Relationship and ListBox control in MVC and Entity Framework
26 Mar 2015 by ramyajaya
This error is a very common error which will occur at the time of initialising the model.in your case it might have occurred if your existing table and the model definition have not matched check on to it.If you really feel it complex check on to this...
8 Mar 2015 by Swetaketu Majumder
The following is a partial of my DB Schema.https://drive.google.com/file/d/0Bx3eJEwRdRm5MkNDcjBoSGI1NVE/view?usp=sharingI have two lists containing parentNames and the leafNames I need. Now, I need to copy the required records from one entity's tables to a newly created entity's...
8 Mar 2015 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
FindControl works for one Row/Item at a time.Refer - RepeaterItem.FindControl Method[^].
8 Mar 2015 by Kornfeld Eliyahu Peter
Please read this[^] to understand how to access controls inside a template...
8 Mar 2015 by Member 11498842
Hi all, I'm trying to retrieve some data from a repeater, the end goal is to send a bunch of data in to a table. I'm using the following to access the repeater, however "FindControl" is underlined:String prodName =...
3 Mar 2015 by Soufiane Rabhi
What you have to know about ADO.NET and Entity Framework
2 Mar 2015 by deepak690
i am using transaction scope in my project. Isolation level is IsolationLevel.ReadCommitted i Also tried IsolationLevel.RepeatableRead using (DBOperations dboperation = new DBOperations()) { GetAccountVoucherNuber(); }i am calling this method from Transaction...
1 Mar 2015 by PiyushMCA
How to Delete Multiple Records in Entity Framework 5 using Repository Pattern?Please Help.
26 Feb 2015 by Sergey Alexandrovich Kryukov
Please show the fragment of the database schema and your SQL statement. If possible, devise as small statement as possible, still manifesting this problem.—SA
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.
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,...
12 Feb 2015 by sagar wasule
Resolved this by disabling the lazy loading functionality in context class constructor as below,this.Configuration.LazyLoadingEnabled = false;
12 Feb 2015 by sagar wasule
Hi All,I'm learning Entity Framework, while trying out Database First Approach.I added an Entity Model to the project and created an API controller using Entity Framework. By just browsing the get method from the API controller Created I found that the data is obtained in json format which...
23 Jan 2015 by sharif_gabbar
Here is the case:I have an existing project created using entity framework. Now I have to create a new form and save its data to a new table using enterprise library. But the catch is that I have to do it without refreshing the existing edmx of the project. When I am calling the insert...
8 Jan 2015 by srinivas vadepally
Hi,I have a below property in my model. public IDictionary> Privileges { get; private set; } I have googled but didn't find any solution to map Dictionary using fluent api.Does EF supports IDictionary mapping?
28 Dec 2014 by Suraj Sahoo | Coding Passion
You are out for learning a lot of things. So all the best for learning MVC. :)1- Now for your queries in the question, we cannot provide you the entire architecture for this project. But keep in mind to learn and implement the architecture so that the project is loosely coupled so that it...
28 Dec 2014 by Dhaneshmon
I am very new to ASP.Net MVC. I am planning to create on website for classifieds. So I would like to get url as following(http://mysitename.com/stateName/Place/Furniture/34)From admin panel I should able to create StateName,Place, Category(eg. Furniture)I am planning to start...
12 Dec 2014 by Nathan Minier
You're asking about two structures that do completely different things. A List is a robust collection that supports inserts as well as a few other utility functions that make it more robust than []. There is an excellent primer on enumerable types at:List vs IEnumerable vs IQueryable vs...
11 Dec 2014 by Member 11286130
Which is better and fast IQueryable or List
1 Dec 2014 by Amit Kumar143
i created a wcf web service. my service uses EF5 data acceess to fetch data.i have only one function named GetAllAdminList() code: IAdminService.cs public interface IAdminService { [OperationContract] List GetAllAdminList(); }And...
26 Nov 2014 by Mukesh Pr@sad
Hi kishore, U can acheive this task using following syntax:- var blogs = context.Blogs.SqlQuery("SELECT * FROM dbo.Blogs").ToList(); Here context is ur context object , blogs is the table name after that you have to write.SqlQuery() and inside that u can write ur...
26 Nov 2014 by Y Kishore Kumar
Hi Experts, I want to know that is it possible to write sql Queries with EF if yes then please tell me how to write.Thanks
24 Nov 2014 by Sandeep Singh Shekhawat
Hi,The ADO.NET Entity Framework allows developers to choose any one approach among three possible approaches: Database First, Model First and Code First.Database First: It is a more data-centric design that is based on an existing database. The Entity Framework is able to generate a...
24 Nov 2014 by King Fisher
I'm gonna create a new MVC Application. which is best EF Code First ? Model First? Db First ? I don't have fixed Database Design ,i may modify existing table may add new table . so which one is Suitable for my Requirement
24 Nov 2014 by Suraj Sahoo | Coding Passion
Quote:I don't have fixed Database Design ,i may modify existing table may add new table .As you say here, I anticipate you already have a database and may be you need modification in there in future. So I would suggest to opt for Database first approach. As you just need to add your database...