Unable to use stored procs in a generic repository for the entity framework. (ASP.NET MVC 2)
Posted
by Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2010-06-12T06:28:33Z
Indexed on
2010/06/12
6:32 UTC
Read the original article
Hit count: 317
Hi,
I have a generic repository that uses the entity framework to manipulate the database.
The original code is credited to Morshed Anwar's post on CodeProject. I've taken his code and modified is slightly to fit my needs.
Unfortunately I'm unable to call an Imported Function because the function is only recognized for my specific instance of the entity framework
public class Repository<E, C> : IRepository<E, C>, IDisposable
where E : EntityObject
where C : ObjectContext
{
private readonly C _ctx;
public ObjectResult<MyObject> CallFunction()
{
// This does not work because "CallSomeImportedFunction" only works on
// My object. I also cannot cast it (TrackItDBEntities)_ctx.CallSomeImportedFunction();
// Not really sure why though... but either way that kind of ruins the genericness off it.
return _ctx.CallSomeImportedFunction();
}
}
Anyone know how I can make this work with the repository I already have? Or does anyone know a generic way of calling stored procedures with entity framework?
Thanks,
Matt
© Stack Overflow or respective owner