Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stored Functions with Linq to Entities

How can I make a MS-SQL stored function availabe in LINQ expressions if using the Entity framework?

The SQL function was created with CREATE FUNCTION MyFunction(@name) ...). I was hoping to access it similarly to this:

var data = from c in entities.Users where MyFunction(c.name) = 3;

Unfortunately I have only .NET 3.5 available.

like image 852
Stefan Avatar asked Dec 05 '25 15:12

Stefan


1 Answers

You actually can import DB functions in EF 1. But you don't get EdmFunctionAttribute in EF 1, so you're limited to the contexts where you can use them. You need EF 4 for that.

For your case you might want to consider mapping a proc returning Users (for 3.5; again, 4 is better for this feature).

like image 180
Craig Stuntz Avatar answered Dec 07 '25 03:12

Craig Stuntz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!