Thursday 15 July 2010

c# - Entity Framework with optional parameters? -


Using Entity Framework 5 It is possible to use a stored proc with such a preferred parameter, Do not need to add each unused parameter?

The stored procedure I use is 87 parameters, of which only 2 are required. I really hate the idea of ​​putting 85 tap in each call.

You can use the method ( DbContext to perform some stored procedure and list the parameters To execute, there is a wrapper on ObjectContext :

  FooEntities db = new FooEntities (); var objectContext = ((IObjectContextAdapter) DB.) ObjectConnectX; // To create the parameter you need the name var = new object peer ("name", "lazy"); Var age = new object punter ("age", 29); // Called with these two parameters. Recovery is the only var result = objectContext.ExecuteFunction & lt; result & gt; ("ProcedureName", name, age);   

You can change your code to your DbContext For the extension method, you can wrap:

  public static result process name (this FooEntities db, name, age) {// code above}   

Will be used as: var result = db.ProcedureName ("lazy", 29);

No comments:

Post a Comment