I have implemented Generic repository and UOW using this link
http://blog.longle.net/2013/05/11/genericizing-the-unit-of-work-pattern-repository-pattern-with-entity-framework-in-mvc/
Now I want to call stored procedure.I am using Entity Framework version 5.
Please advice me How to call a stored procedure
Related
I need to execute a stored procedure with Entity Framework.
Normally I call it like this:
this.Context.Database.ExecuteSqlCommand("EXEC edi_UploadTransmission");
However, this particular stored procedure includes accessing a linked server.
Since EF wraps ExecuteSqlCommand in a transaction, it is failing, as a linked server is not supported in a transaction (as far as I can tell).
Is there a way to execute this stored procedure with Entity Framework without it being in a transaction?
Pass TransactionalBehavior.DoNotEnsureTransaction as the first parameter to the ExecuteSqlCommand method.
For example,
this.Context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, "EXEC edi_UploadTransmission");
My recommendation would be to simply not use EF for this part of your code. You can freely combine EF with straight ADO.NET code or with other ORMs such as Dapper or Chain.
https://github.com/docevaad/Chain/wiki/A-Chain-comparison-to-Dapper
i want use the Entity Framework with Catel to use the UoW pattern in my code. I have reade this article:
http://www.geertvanhorrik.com/category/catel/page/2/
I create a new Project with the name "Database". In this project i implement my Application Models. At the moment i store the data in a XML file but i want store it in a SQL Database in the future. My models a derived from "SaveableModelBase".
public class SettingsDataObject : SavableModelBase
1) What must i do to use the Entityframework? Is there a EntityModelBase or something?
2) How i must design my model classes?
2) How i register the Repositories with the ServiceLocator? RegisterType< ..., ...>?
3) Can i use the "Code First" and AutoGenerate Database Tables in Catel?
Where i can find a good basic code Example to implement the UoW pattern with Catel?
What must i do to implement a UoW with Catel?
I hope anybody can help me,
Thank you & Greetings
Catel does not provide base classes for Entity Framework. EF is normally used in combination with SQL server databases. It cannot be used in combination with the SavableModelBase.
For more information, see the official documentation:
https://catelproject.atlassian.net/wiki/display/CTL/Catel.Extensions.EntityFramework5
I've got an application with MVC and Entity Framework. The application uses Unit of Work and Repository patterns for CRUD operations. But I've got to add now a couple of stored procedures that already exist in database. One of them just retrieves data from one of the entities (this is achieved at this moment by the repository pattern) but adds an extra column to the final result, created and populated in the stored procedure.
I want to integrate the use of these stored procedures into my architecture. I've tried to add the stored procedures to my model, map it to the class and use it, but as I have to add an extra column to this entity in the model, I get an error that this field is not mapped.
Should I use my repository for this particular entity just for Add/Edit/Delete and create another entity with the extra field that will be used for just the Get action using the stored procedure?
Thanks.
Should I use my repository for this particular entity just for Add/Edit/Delete and create another entity with the extra field that will be used for just the Get action using the stored procedure
Depends on the use case? Sounds like it's used for a different case and if so I would create a new entity for it.
This question is an extension of another question, but I think it warrants its own thread. See See Silverlight Question
I have a stored procedure (SQL 2005) that returns a dynamic data set (different columns/schema) each time it is called.
I want to consume this in Silverlight 3.0 so I need to somehow wire this up using Entity Framework and RIA Services. I also need this to be Bindable (Silverlight Grid) so I need these dynamic columns to be accessible via properties (grid limitation). Any ideas?
In the currently shipping version of the Entity Framework, the only type of stored procedures you can map are those which return entity types. The mapping is done, generally, before you compile, although it seems at least theoretically possible to generate Entity Framework metadata at runtime.
Therefore, I see a few choices.
Give up on the whole idea of consuming a procedure which does not return a defined schema. You will never be able to map such a procedure before you compile.
Dynamically generate EDMX at runtime in order to map an entity type to the expected output columns of the procedure before you invoke. Note that the current version of the Entity Framework is a bit finicky about the columns a procedure returns; you can find documentation about this on MSDN.
In .NET 4.0, there are new features which allow you to inform the Entity Framework about your client schema at runtime without having to generate EDMX first. You might be able to leverage these features in order to map some entity type to the expected output columns of the procedure.
Again, in .NET 4.0, there may be support for procs which return scalar values. I can't remember if this is the case or not.
You can always get a standard database connection from the entity connection and execute the procedure directly, using regular SqlCommands. Unfortunately, this makes your code database-provider-specific, but it may be the simplest solution to your problem. Indeed, using such a procedure at all is already database-server-specific.
You might use a WCF web service wraper for accesing your SP and use the WCF service as data source Brad Abrams has a way to do that on his series of articles on RIA Services
In LINQ2SQL it was possible to set the return type of a stored procedure to auto generated.
I am unable to do so with the Entity Framework.
I want to set the return type of a stored procdure to auto-generated with the Entity Framework.
Is this possible?
Kind regards.
Entity Framework V1 has good support for working with Stored Procedures directly with entities (as Insert/Update/Delete operations) but as you have discovered, out of the box the support for SPs as functions on your ObjectContext is poor. They pretty much always have to map perfectly to an existing entity in your model as the expectation was you would then do changes to the returned results from the SP and hence would want to work with them as entities. Clearly this is not always the case.
Thankfully there are extensions for EF v1 which include improved support for SPs. Download the extensions here.
EF v2 will have better support.