Ralms.EntityFrameworkCore.Extensions for EntityFramework Core
DateDiff & Query Hints (Only SQL Server)
var list = db
.People
.Where(p => EFCore.DateDiff(DatePart.day, DateTime.Now, p.Birthday) < 50)
.ToList();
// Enable Extension
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=SampleExtension;Integrated Security=True;")
.RalmsExtendFunctions();
}
// Sample Use
var list = db
.People
.WithHint(SqlServerHints.NOLOCK)
.Take(1)
.ToList();
var list = db
.People
.WithHint(SqlServerHints.UPDLOCK)
.Take(1)
.ToList();
SELECT [b].[Id], [b].[Date], [b].[Name]
FROM [Blogs] AS [b] WITH (UPDLOCK)
- New extension to design the SQL output
var sql = _db
.Blogs
.Where(p => EFCore.DateDiff(DatePart.day, DateTime.Now, p.Date) < 50)
.ToSql();
Output SQL
SELECT [p].[Id], [p].[Date], [p].[Name]
FROM [Blogs] AS [p]
WHERE DATEDIFF(day, GETDATE(), [p].[Date]) < 50