-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFun.cs
More file actions
26 lines (25 loc) · 757 Bytes
/
Copy pathFun.cs
File metadata and controls
26 lines (25 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Data.Entity;
namespace UdfCodeFirstSample
{
public static class Fun
{
[DbFunction("CodeFirstDatabaseSchema", "GetAge")]
public static int? GetAge(DateTime? birthDate)
{
// this in-memory implementation will not be invoked when working on LINQ to Entities
// see Migrations for the T-SQL definition of the function
int? age = null;
if (birthDate.HasValue)
{
var today = DateTime.Today;
age = today.Year - birthDate.Value.Year;
if (birthDate > today.AddYears(-age.Value))
{
age--;
}
}
return age;
}
}
}