digipolisantwerp / dataaccess_aspnetcore_deprecated

Generic repository/unit of work framework for ASP.NET Core with Entity Framework.
Other
140 stars 45 forks source link

Stored Procedure #21

Closed coskuncinar closed 8 years ago

coskuncinar commented 8 years ago

Hİ, This architecture is very good, İ have a question , when i want to use stores procedure in query ('for full text search ') how to inject ?

could you take example pls ?

StevenVandenBroeck commented 8 years ago

You can make a custom repository with our framework and provide methods on it where you execute store procedures. : https://github.com/digipolisantwerp/dataaccess_aspnetcore#custom-repositories.

The stored procedures can be called with the FromSql method on the DbSet :

var blogs = context.Blogs.FromSql("EXECUTE dbo.GetMostPopularBlogs").ToList();

coskuncinar commented 8 years ago

Actullay last question and this question interconnected. Namely, let's say i have stored procedure for fulltext search. i have 3 table(stock,stockdetails,stockcolor) . there are 10 entries in the first table there are 2 entries in the first table there are 5 entries in the first table

relations is stock.Id<-stockdetails.stokId and stock.stokColorId>-stockcolor.StokId i wanna 15 column in stockkstatu . but it dont result 15 column. because dbset is result 10 var stockkstatu = context.'stock'.FromSql("EXECUTE dbo.GetStockStatu").ToList(); if i use as this . it cannot run. (i trid) :/

Is there another way?

StevenVandenBroeck commented 8 years ago

That is not possible with the current version of Entity Framework Core. You can only use stored procedures that will be directly mapped to a defined model, no projections. You can find a feature comparison here : https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html?highlight=non-model. Apparently it is planned for Q1/2017, their roadmap for v1.1 is here : https://blogs.msdn.microsoft.com/dotnet/2016/07/29/entity-framework-core-1-1-plans/

StevenVandenBroeck commented 8 years ago

Do you need a stored procedure ? Can't you do the same query with Linq, including the related tables via the Navigation Properties ?

coskuncinar commented 8 years ago

Thank you your answer, but efcore need to put back at least a few of the old property for example withoutjoin. https://docs.efproject.net/en/latest/efcore-vs-ef6/features.html Efcore is looking good but its not enough. I need new question but i will create under new title.