Add example user-defined function.
This commit is contained in:
parent
093c663b31
commit
001e78736c
@ -17,6 +17,21 @@ context.Database.EnsureCreated();
|
||||
// var firstCoach = await context.Coaches.FirstOrDefaultAsync();
|
||||
|
||||
|
||||
async Task UserDefinedQuery()
|
||||
{
|
||||
var earliestMatch = context.GetEarliestTeamMatch(1);
|
||||
// This is done, if you have a user-defined function in the database.
|
||||
// for example:
|
||||
// CREATE FUNCTION [dbo].[GetEarliestMatch] (@teamId int)
|
||||
// RETURNS datetime
|
||||
// BEGIN
|
||||
// DECLARE @result datetime
|
||||
// SELECT TOP 1 @result = date
|
||||
// FROM MATCHES [dbo].[Matches]
|
||||
// ORDER BY Date
|
||||
// return @result
|
||||
// END
|
||||
}
|
||||
|
||||
async Task QueryScalarType()
|
||||
{
|
||||
|
||||
@ -41,5 +41,16 @@ public class DeadBallZoneLeagueDbContext : DbContext
|
||||
|
||||
// This database object does not have a Primary Key, so we state that here, otherwise an exception is thrown.
|
||||
modelBuilder.Entity<TeamsAndLeaguesView>().HasNoKey().ToView("vw_TeamsAndLeagues");
|
||||
|
||||
// This is for user-defined functions.
|
||||
modelBuilder.HasDbFunction(
|
||||
typeof(DeadBallZoneLeagueDbContext)
|
||||
.GetMethod(
|
||||
nameof(GetEarliestTeamMatch),
|
||||
new[] {typeof(int)}
|
||||
))
|
||||
.HasName("GetEarliestMatch");
|
||||
}
|
||||
|
||||
public DateTime GetEarliestTeamMatch(int teamId) => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user