.NET SQL Functions Class

If you use Entity Framework you will enjoy learning about the SQL Functions Class. The SQL function class provides a way to call common database functions in your Entity Framework LINQ queries.

There are too many functions provided by this class to cover them all. You will find some classic SQL functions like Stuff and GetDate. You will also find mathematical functions such as PI and Log.

It is important to note that these functions can only be called within the context of the LINQ to Entity queries. An example of how you would use these functions is as follows:

var results = _testContext.Persons
.Where(x => x.CreateDate >= SqlFunctions.GetDate())
.ToList();

Assert.AreEqual(1, results.Count);
Assert.AreEqual("Sam", results.First().Name);

More Information

You can explore the many functions provided by the SQLFunctions class on MSDN. This class will not be avaliable in the .NET Core project. To see a list of libraries that will be avalible in the .NET Core project check out the corefx-progress GitHub repository.

Comments

comments powered by Disqus