Error calling a UDF from Entity Framework LINQ query -


i'm running issue calling user defined function linq query. i'm using .net 4.0 framework , vs 2010. here snapshot of xml edmx function definition.

  <schema namespace="mystoredwmodel.store" alias="self" provider="system.data.sqlclient" providermanifesttoken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/entitystoreschemagenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">     <function name="regularprice" store:name="regularprice" iscomposable="true" schema ="mystoredwextension.mystore" aggregate="false" builtin="false" returntype="decimal" storefunctionname="fn_getprice">       <parameter name="productid" type="varchar" scale="40" mode="in"/>       <parameter name="pricetypeid" type="varchar" scale="10" mode="in"/>       <parameter name="groupcode" type="varchar" scale="10" mode="in"/>       <parameter name="groupvalue" type="varchar" scale="10" mode="in"/>       <parameter name="effectivedate" type="datetime" mode="in"/>     </function> 

i have following function stub defined in code ...

[edmfunction("mystoredwmodel.store", "regularprice")] public decimal? regularprice(     string productid,     string pricetypeid,     string groupcode,     string groupvalue,     datetime effectivedate) {     throw new notimplementedexception("you can call method part of linq expression"); } 

the call i'm using access function follows ...

 mystoredwentities4 test = new mystoredwentities4();   var prices = (from products in test.products                select regularprice("productid", "r", "d", "20", datetime.now)); 

when attempt access prices data receive following error ...

    specified method 'system.nullable`1[system.decimal] regularprice (system.string, system.string, system.string, system.string, system.datetime)' on type 'entityframeworktest.form1' cannot translated linq entities store expression because instance on invoked not objectcontext on query in used evaluated. 

i've attempted several variations of configuration , call no avail. has run across error before , steps might use fix it?

try place regularprice method mystoredwentities4 class definition (use partial declaration in following example):

public partial class mystoredwentities4 {   [edmfunction("mystoredwmodel.store", "regularprice")]   public decimal? regularprice(     string productid,     string pricetypeid,     string groupcode,     string groupvalue,     datetime effectivedate)   {     throw new notimplementedexception("you can call method part of linq expression");   } }   

then call objectcontext instance method, here:

objectset<products> products = test.products;   var prices = prod in products                select new { price = test.regularprice("productid", "r", "d", "20", datetime.now)}; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -