Why is ExecuteFunction method only available through base.ExecuteFunction in a child class of Object

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-06-08T05:02:25Z Indexed on 2010/06/08 5:12 UTC
Read the original article Hit count: 453

I'm trying to call ObjectContext.ExecuteFunction from my objectcontext object in the repository of my site.

The repository is generic, so all I have is an ObjectContext object, rather than one that actually represents my specific one from the Entity Framework.

Here's an example of code that was generated that uses the ExecuteFunction method:

[global::System.CodeDom.Compiler.GeneratedCode("System.Data.Entity.Design.EntityClassGenerator", "4.0.0.0")]
public global::System.Data.Objects.ObjectResult<ArtistSearchVariation> FindSearchVariation(string source)
{
    global::System.Data.Objects.ObjectParameter sourceParameter;
    if ((source != null))
    {
        sourceParameter = new global::System.Data.Objects.ObjectParameter("Source", source);
    }
    else
    {
        sourceParameter = new global::System.Data.Objects.ObjectParameter("Source", typeof(string));
    }
    return base.ExecuteFunction<ArtistSearchVariation>("FindSearchVariation", sourceParameter);   
}

But what I would like to do is something like this...

public class Repository<E, C> : IRepository<E, C>, IDisposable
    where E : EntityObject
    where C : ObjectContext
{
    private readonly C _ctx;

    // ...

    public ObjectResult<E> ExecuteFunction(string functionName, params[])
    {
        // Create object parameters

        return _ctx.ExecuteFunction<E>(functionName, /* parameters */)
    }
 }

Anyone know why I have to call ExecuteFunction from base instead of _ctx?

Also, is there any way to do something like I've written out? I would really like to keep my repository generic, but with having to execute stored procedures it's looking more and more difficult...

Thanks,
Matt

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about entity-framework