Today is a study of the day of the Sqlfunctions, consulted a few groups of cattle, incredibly found that everyone is more unfamiliar with this,
Some even pointed to the method in EF that cannot be called in SQL Server.
Because I've had a Sqlmethod in LINQ to SQL before, I think EF must be able to do it.
First of all, a short introduction to EF6 and EF5, when you nuget a EF5 package, only entityframework, and EF6 do EntityFramework and Entityframework.sqlserver,
There are a lot of differences between the 2 of them.
In the EF5 environment, how do we use sqlfunctions?
First add the EF environment, add Syste.Data.Entity to the reference, and then add the namespace
using System.Data.Objects.SqlClient;
Then write a controller test
1 Publicactionresult Index ()2 {3 intCount =0;4 using(Models.testprojectdbentities db =Newmodels.testprojectdbentities ())5 {6 varQuery = fromCinchDb. AdmininfoeswhereSqlfunctions.square (1.00) ==c.ordersSelectC;7Count =query.tolist (). Count ();8 }9Viewbag.count =Count;Ten returnView (); One}
is operating normally.
EF6 Environment,
There are entityframework and entityframework.sqlserver in our references,
Then we add the namespace
using System.Data.Entity.SqlServer;
Notice, and EF5 under the namespace is not the same, this place I also have a misunderstanding, when my add is using System.Data.Objects.SqlClient;
This error is really strange, I find a lot of reasons on the internet has not been found, the last chance to get this result.
Then we run the above test code, it should also run through.
Sqlfunctions provides a lot of methods, this is relatively simple, do not do a detailed introduction.
This group provides ASP. NET Mvc,ef,linq,web API technical support, do not care about people, care about human spermatogonial.
ASP. NET MVC Group 171560784
Invite all the experts, beginners to join.