in EF5 Environment , first add EF environment, add Syste.Data.Entity in reference, add 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.
in the EF6 environment , there are entityframework and entityframework.sqlserver in our references, and then we add namespaces using System.Data.Entity.SqlServer;
Notice, and EF5 under the namespace is not the same, this place I also appeared a misunderstanding, when my add is using System.Data.Objects.SqlClient; has been an error,
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.
Sqlfunctions can call SQL Server functions in EF