Stored procedure in Entity framework with multiple parameters in mvc3 - asp.net-mvc-3

I am new in entity framework and mvc3.how can i execute Stored procedure in Entity framework with multiple parameters in mvc3.

This depends if you are using code first or not. I do agree with the folks above you could've probably easily researched this but I'll provide an overview here so it's all in one spot to review as there are several options to consider.
With code first in the latest version of EF 6 Beta, you can execute stored procs as part of code-first as described in the docs here
Prior to EFv6 you could use the following to execute a proc in your code and map to an entitycontext.Database.SqlQuery<YourEntityType>
If you aren't using code first, you can map in the designer as explained by Julie Lerman many places, but one easy link is here

Related

How do you build OData IEdmModel from Entity Framework model

The title says it all really. I've found several blogs with different ways (serializing the EF model to XML and then de-serializing again to the IEdmModel was one) but they're all based on old version of the OData package.
Serializing is the only way.
Example.
Relevant work.
I've ranted about this a few months ago. AFAIK nothing changed since then, and I personally don't expect them to change too much. The short story is that as of September 2012, there is no plan to use EdmLib in EF, nor is there to use EF's code in other projects.
How much should we align with OData’s EdmLib?
Not worth adopting code
Cost of implementing SSDL & MSL
Freedom to evolve our API independently
Look at aligning names of types and properties where appropriate
If your DbContext is being built from a database-first approach the given answer will fail giving this error:
Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.
After some time messing with this I have found an appropriate solution. Basically you grab the CSDL resource from the assembly containing the DbContext in question and parse it using the Microsoft.Data.Edm.Csdl.CsdlReader.TryParse method. The resulting IEdmModel is valid containing the exact information given by EntityFramework when the model was built.
See here for an example with usage

Returning child elements in ASP.NET WebAPI OData

I'm using the latest ASP.Net WebAPI Nightly builds (dated 2013-01-16).
I have a simple EF database first model at the moment that has two entities - Patients and Visits. Each patient can have many visits.
I'd like to be able to query for my list of patients and have the visits entities for each patient returned inline. I know that WebAPI's OData implementation doesn't yet support $expand. I'm hoping that just means that optional client-controlled expansion is not supported and that I can force expansion server-side.
At the moment I'm not getting any of the visits inline.
For example, my PatientController's() Get() method looks like
[Queryable(AllowedQueryOptions=AllowedQueryOptions.Supported)]
public override IQueryable<Patient> Get()
{
var query = this.entities.Patients.Include("Visits");
return query;
}
I've verified that the query executing against my database does indeed include the visit information.
To use a publicly available OData service as an example, if you use the service at http://services.odata.org/OData/OData.svc/, you can get a list of Suppliers. This is http://http://services.odata.org/OData/OData.svc/Suppliers.
You can also ask for a list of suppliers that includes the list of products using http://http://services.odata.org/OData/OData.svc/Suppliers?$expand=Products
Stepping through the ASP.NET code (via the symbols server) I've got to the System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer and can see that it's CreatePropertyBag method, which builds up the list of properties to be serialized, just doesn't include the navigation properties, and they don't seem to be enumerated anywhere else apart from being written out as NavigationLinks.
I'm quite new to the ASP.NET world in general and have spent a week or so getting my head around the way things work (particularly with the changes made to OData at the end of 2012 and further changes made so far in 2013).
I suspect that if the ODataEntityTypeSerializer was to be modified (I'm happy to try) to embed this extra information in the appropriate spot (within each navigation link as an nested inline feed as best I can tell) then I'd be set.
Questions:
Have I overlooked something obvious and there's a flag I can set to turn on this behaviour? I can see why, if such a flag exists, it would be off by default (EF lazy loading and this flag wouldn't get on well)
If #1 is no, is there some other ODataEntityTypeSerializer that I could use? If so, how do I switch to it?
If #2 is no, any pointers for where I should start writing my own? Is there a place I can substitute in my own serializer or do I have to maintain my own fork of ASP.NET's Extensions project (as opposed to the Runtime project)
Thanks very much!
$expand is very high on our list of things to support for OData. But as far as I know, we don't have any flag to turn it on server-side. The formatter doesn't currently allow you to substitute your own serializers either. So I'm afraid your only option in the meantime is to create a fork and add support for $expand. If you manage to get it working, please consider sending a pull request our way:
http://aspnetwebstack.codeplex.com/SourceControl/network
You can try it already in webapi nightly builds.
Here is how to install it with nuget:
http://aspnetwebstack.codeplex.com/wikipage?title=Use%20Nightly%20Builds

.NET 4.5, EF 5 and MembershipProvider

Does anyone know if there is going to be created a default MembershipProvider to use with EF 5 (like SqlMembershipProvider and ActiveDirectoryMembershipProvider) or we will still have to create custom ones (that is for Code First of course)?
Actually after the long comments and explanations it results that there will be a default MembershipProvider for EF and - guess what, guess what - it is called EFMembershipProvider. Here is a link.Now this is really cool because third party implementations of MembershipProvider will no longer be needed (or the respective manual implementation - it was kind of BIG and total overkill for small projects).
UPDATE
Currently it seems that this provider is not available. I do not know if it will be developed and included in the future either.
Since we are encouraged to use SimpleMembershipProvider and migrations when using EF Code First that is what I am doing now. You can also implement the ExtendedMembershipProvider, which requires a little bit more effort.
For me the best solution for now is to inherit SimpleMembershipProvider and modify only the things that I need (I am using most of the code from my previous implementation of MembershipProvider), for example logging with email or username.
I've implemented a CodeFirst MembershipProvider & Role with my Silversite CMS ASP.NET library, that can be found at silversite.codeplex.com. The library also supports multiple DbContexts for CodeFirst databases.
As far as I know though currently the implementation is broken, and I didn't have the time to fix it yet. Also Profile and Session providers still are lacking. But I've got the code from the MySql providers that should not be too hard to port.

function import in entity framework

As the MSDN says
Do one of the following from the Model Browser:
Open the Stored Procedures folder (in the storage model information) and double-click a stored procedure that does not have a corresponding function import.
- OR -
Right-click the Function Imports folder (in the EntityContainer node of the conceptual model information) and then select Add Function Import.
The Add Function Import dialog box appears.
How can I do function import if my db contains hundreds of sps. Should I go to each sp and do the steps above :( .. It makes no sense.
I have a very large Entity Framework model and I use the Huagati DBML/EDMX tools. It was able to bulk add new tables, views and columns that were in the database but not in the EDMX. It saved a lot of manual work. I haven't used it for stored procedures but it looks like it supports it. Even better, they have a free trial so you can always give it a try to see if it will work for you.
Edit: It also sounds like they have made some improvements to this in the latest version of EF - the June 2011 CTP. This blog post states:
There are several new features for the Entity Framework Designer
within Visual Studio:
[...]
When you import stored procedures using the Entity Model Wizard,
you
can now batch import your stored procedures as function imports.
The
result shape of each stored procedure will automatically become a
new
complex type in your entity model. This makes getting started with
stored procedures very easy.
If you don't want to use a CTP, this blog post says they might have the official version out next month.

How to generate BlToolkit model

From what I have seen on the ormbattle.net, BlToolkit is the fastest ORM for .NET. I would like to test it in one of my projects, but I don't know how to generate entity classes. Should I do this by hand? I have 20+ tables in the database.
Is there any online tutorial or blog, where I can find more information about BlToolkit?
It looks like a library with great potential without community behind it.
you can use our project on bltoolkit code generation:
http://sogen.codeplex.com/
There are the following options:
T4 templates are available for some databases - http://www.bltoolkit.net/Doc.T4Templates.ashx
MyGeneration and template for BLToolkit.
Classes generated for Linq 2 SQL. BLToolkit can use L2S metadata.

Resources