Call stored procedure from LINQ (with dbcontext)
Hello everybody With EF4, i can map a EDMX function (with "update model from database" and add a stored procedure from the list) to a linq method by using a small snippet like this
[EdmFunction("MYPROJECT.Store", "Foo")]
public Decimal Foo(Int32 Id)
{
throw new NotSupportedException("Not direct access possible, use with E-SQL or LINQ");
}
But this开发者_如何转开发 seems not working with EF 4.1
I see that stored procedures don't work with Code First. I'm using DbContext, is it normal that i can't do that ?
If yes, how can i make my stored procedures working ?
Thank's by advance :-)
This is only EDMX related feature and you can't use it with DbContext API code first / fluent API without EDMX. Btw. you mean SQL function and not stored procedure because imported stored procedure results in function import and cannot be called in Linq query. Methods marked with EdmFunction
states either for imported SQL functions and model defined functions.
Yes I know, SQL functions appears under the stored procedures branch in the import wizard but that is just "feature" of EDMX designer.
Because you are using database-first with DbContext API and EDMX file you should be able to use EdmFunction
without any problem. I just tested it. The problem probably is that your proxy method marked with EdmFunction
attribute is not static - it must be static.
精彩评论