i wrote the SP in sqlserver 2008.Please tell me how to use that SP in entity framework?
Hello:)
1)Create an edmx file,you should also import the SP as functions in the wizard window。
2)Then double click your edmx file and then right click your model,and then choose Function Import……In the pop-up dialog,choose the SP that you want to import as a function。
3)Then you can use it through the database contenxt,just like this:
using (EntityContext ec = new EntityContext())
{
ec.YourStoredProcdure's FunctionName here(Parameters……);
}
Getting " The data reader is incompatible with the specified 'Model.List'. A member of the type, 'id', does not have a corresponding column in the data reader with the same name.
venkateswara...
Member
16 Points
78 Posts
How to call stored Procedure in entity framework ?
Mar 30, 2012 07:12 AM|LINK
Hi,
i wrote the SP in sqlserver 2008.Please tell me how to use that SP in entity framework?
Thanks in advance...
Steelymar
All-Star
15283 Points
2239 Posts
Re: How to call stored Procedure in entity framework ?
Mar 30, 2012 07:27 AM|LINK
http://msdn.microsoft.com/en-us/library/bb896279.aspx
Stefan Uzunov
MCTS: .NET Framework 3.5 ASP.NET Applications
me_ritz
Star
9339 Points
1448 Posts
Re: How to call stored Procedure in entity framework ?
Mar 30, 2012 07:43 AM|LINK
These links might be useful to you
http://weblogs.asp.net/dotnetstories/archive/2011/03/01/using-stored-procedures-with-entity-framework-in-an-asp-net-application.aspx
http://beyondrelational.com/modules/2/blogs/64/posts/11620/entity-framework-40-bind-stored-procedure-with-result-entity-class.aspx
Thanks
tdykstra
Contributor
4523 Points
630 Posts
Microsoft
Moderator
Re: How to call stored Procedure in entity framework ?
Mar 30, 2012 01:58 PM|LINK
For Database First / Model First you can set up EF to call the SPs automatically:
http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-7
For Code First you have to call them manually:
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/advanced-entity-framework-scenarios-for-an-mvc-web-application
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to call stored Procedure in entity framework ?
Apr 01, 2012 12:17 AM|LINK
Hello:)
1)Create an edmx file,you should also import the SP as functions in the wizard window。
2)Then double click your edmx file and then right click your model,and then choose Function Import……In the pop-up dialog,choose the SP that you want to import as a function。
3)Then you can use it through the database contenxt,just like this:
using (EntityContext ec = new EntityContext()) { ec.YourStoredProcdure's FunctionName here(Parameters……); }venkateswara...
Member
16 Points
78 Posts
Re: How to call stored Procedure in entity framework ?
Apr 02, 2012 01:24 PM|LINK
List<GetDevices> list = null;
var result = (from a in ec.usp_GetDevices(1,"ios","class1","test@gmail.com")
select new { a.deviceid}).Distinct();
list = result.AsEnumerable()
.Select(o => new GetDevices
{
deviceid = o.deviceid
}).ToList();
i added my SP as addfunctionimport and complexttype given as GetDevices .why i am getting list as empty always if records are there in table.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to call stored Procedure in entity framework ?
Apr 03, 2012 02:55 AM|LINK
Plz use entity type as a return type ……
Reguards!
venkateswara...
Member
16 Points
78 Posts
Re: How to call stored Procedure in entity framework ?
Apr 03, 2012 05:05 AM|LINK
in entitytype selected "classname" .
Getting " The data reader is incompatible with the specified 'Model.List'. A member of the type, 'id', does not have a corresponding column in the data reader with the same name.
venkateswara...
Member
16 Points
78 Posts
Re: How to call stored Procedure in entity framework ?
Apr 03, 2012 05:14 AM|LINK
Thanks .....i got it
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to call stored Procedure in entity framework ?
Apr 04, 2012 12:52 AM|LINK
Congratulations!If possible,would you mind offering me your solutions and mark as an answer?
Reguards!