Exception When One Compiled Query Called in Another Compiled Query

Posted by kgovindarao523-21772 under C# on 2/10/2014 | Points: 10 | Views : 3098 | Status : [Member] [MVP] | Replies : 4
Hi,

I am using linq to entities compiled queries to retrieve result set using Ado.net Entity model in VS2010.

 
Func<double, double> sqr = x => x * x;
var compiledQuery = CompiledQuery.Compile((MYENTITYCONTEXT context) =>
from r in context.MYTABLE
where sqr(r.ID) > 15
select r
);
MYENTITYCONTEXT objDB=new MYENTITYCONTEXT();
var result = compiledQuery.Invoke(objDB);

string s = string.Empty;
foreach (var item in result )
{
s += item.EMPNAME;
s += " *** ";
}
Console.WriteLine(s);


I am getting exception at result saying that
"The LINQ expression node type 'Invoke' is not supported in LINQ to Entities."

Provide me a solution how to do this.
Please do not put links by googl ing it.

Thanks in advance

Thank you,
Govind



Responses

Posted by: raghuavulapalli-25110 on: 2/10/2014 [Member] Starter | Points: 25

Up
0
Down
Govind,

u should not call compiled query sqr(5) directly in linq query as it doesn't invoke the method.

Try this..
Func<double, double> sqr = x => x * x;

int z = mySqr(5);

var compiledQuery = CompiledQuery.Compile((MYENTITYCONTEXT context) =>

from r in context.MYTABLE

where z > 15

select r

);

MYENTITYCONTEXT objDB=new MYENTITYCONTEXT();

var result = compiledQuery.Invoke(objDB);



string s = string.Empty;

foreach (var item in result )

{

s += item.EMPNAME;

s += " ";

}

Console.WriteLine(s);

It works fine now...

Thanks,
Raghunath.

Raghunath

kgovindarao523-21772, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 2/10/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
refer
http://www.programmingrelief.com/1333741/the-Linq-Expression-Node-Type-invoke-Is-Not-Supported-In-Linq-To-Entities---Stumped

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

kgovindarao523-21772, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 2/10/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
@Raghunath:
I tried like this before posting this forum. It works fine. But I want a dynamic way to call compiled query as specified in the post.
where sqr(r.ID) > 15

Here, Id changes for each record

Thank you,
Govind

kgovindarao523-21772, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravan661 on: 3/1/2014 [Member] Bronze | Points: 25

Up
0
Down
Hi,
http://blog.linqexchange.com/index.php/how-to-use-compiled-queries-in-linq-to-sql-for-high-demand-asp-net-websites/

Revert if you have any issues
Mark as answer if satisifed

sravan

kgovindarao523-21772, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response