Partage via


Mappage de la méthode CLR aux fonctions de chaînes canoniques

Entity Framework fournit un ensemble de fonctions canoniques chargées d'implémenter des fonctionnalités communes à de nombreux systèmes de base de données, notamment la manipulation de chaînes et les fonctions mathématiques. Cela permet aux développeurs de cibler un large éventail de systèmes de base de données. Lorsqu'elles sont appelées via une technologie de requête comme LINQ to Entities, ces fonctions canoniques sont traduites dans la fonction de magasin correspondante du fournisseur utilisé. Les appels de fonction peuvent ainsi être exprimés sous une forme commune dans toutes les sources de données, ce qui procure une expérience de requête cohérente. Les opérateurs au niveau du bit AND, OR, NOT et XOR sont également mappés à des fonctions canoniques lorsque l'opérande est de type numérique. Dans le cas des opérandes booléens, les opérateurs au niveau du bit AND, OR, NOT et XOR calculent les opérations logiques AND, OR, NOT et XOR de leurs opérandes. Pour plus d’informations, consultez Fonctions canoniques.

Pour les scénarios LINQ, les requêtes exécutées sur Entity Framework impliquent le mappage de certaines méthodes CLR aux méthodes au niveau de la source de données sous-jacente au moyen de fonctions canoniques. Les appels de méthode d'une requête LINQ to Entities qui ne sont pas explicitement mappés à une fonction canonique entraîneront la levée d'une exception d'exécution NotSupportedException.

Mappage de la méthode System.String (statique)

Méthode System.String (statique) Fonction canonique
System.String Concat(String str0, String str1) Concat(str0, str1)
System.String Concat(String str0, String str1, String str2) Concat(Concat(str0, str1), str2)
System.String Concat(String str0, String str1, String str2, String str03) Concat(Concat(Concat(str0, str1), str2), str3)
Égal booléen(chaîne a, chaîne b) = (opérateur)
Boolean IsNullOrEmpty(String value) (IsNull(value)) OR Length(value) = 0
Boolean op_Equality(String a, String b) = (opérateur)
Boolean op_Inequality(String a , String b) != (opérateur)
Microsoft.VisualBasic.Strings.Trim(String str) Trim(str)
Microsoft.VisualBasic.Strings.LTrim(String str) Ltrim(str)
Microsoft.VisualBasic.Strings.RTrim(String str) Rtrim(str)
Microsoft.VisualBasic.Strings.Len(String expression) Longueur(expression)
Microsoft.VisualBasic.Strings.Left(String str, Int32 Length) Left(str, Length)
Microsoft.VisualBasic.Strings.Mid(String str, Int32 Start, Int32 Length) Sous-chaîne(str, Start, Length)
Microsoft.VisualBasic.Strings.Right(String str, Int32 Length) Right(str, Length)
Microsoft.VisualBasic.Strings.UCase(String Value) ToUpper(Value)
Microsoft.VisualBasic.Strings.LCase(String Value) ToLower(Value)

Mappage de la méthode System.String (d'instance)

Méthode System.String (d'instance) Fonction canonique Remarques
Boolean Contains(String value) this LIKE '%%value ' Si value n’est pas une constante, ceci est mappé à IndexOf(this, value) > 0
Boolean EndsWith(String value) this LIKE '%value' Si value n'est pas une constante, cela mappe à Right (this, length(value)) = value.
Boolean StartsWith(String value) this LIKE 'value%' Si value n'est pas une constante, cela mappe à IndexOf (this, value) = 1.
Longueur Longueur(this)
Int32 IndexOf(String value) IndexOf(this, value) - 1
System.String Insert(Int32 startIndex, String value) Concat(Concat(Substring(this, 1, startIndex), value), Substring(this, startIndex+1, Length(this) - startIndex))
System.String Remove(Int32 startIndex) Sous-chaîne(this, 1, startIndex)
System.String Remove(Int32 startIndex, Int32 count) Concat(Substring(this, 1, startIndex), Substring(this,startIndex + count +1, Length(this) - (startIndex + count)) La méthode Remove(startIndex, count) n'est prise en charge que si count est un entier supérieur ou égal à 0.
System.String Replace(String oldValue, String newValue) Replace(this, oldValue, newValue)
System.String Substring(Int32 startIndex) Sous-chaîne(this, startIndex +1, Length(this) - startIndex)
System.String Substring(Int32 startIndex, Int32 length) Sous-chaîne(this, startIndex +1, length)
System.String ToLower() ToLower(this)
System.String ToUpper() ToUpper(this)
System.String Trim() Trim(this)
System.String TrimEnd(Char[] trimChars) RTrim(this)
System.String TrimStart(Char[]trimChars) LTrim(this)
Boolean Equals(String value) = (opérateur)

Mappage de la méthode System.DateTime (statique)

Méthode System.DateTime (statique) Fonction canonique Remarques
Égal booléen(DateTime t1, DateTime t2) = (opérateur)
System.DateTime.Now CurrentDateTime()
System.DateTime.UtcNow CurrentUtcDateTime()
Op_Equality booléen(DateTime d1, DateTime d2) = (opérateur)
Boolean op_GreaterThan(DateTime t1, DateTime t2) L’opérateur >
Boolean op_GreaterThanOrEqual(DateTime t1, DateTime t2) >= opérateur
Boolean op_Inequality(DateTime t1, DateTime t2) != (opérateur)
Op_LessThan booléen(DateTime t1, DateTime t2) L’opérateur <
Op_LessThanOrEqual booléen(DateTime t1, DateTime t2) <= opérateur
Microsoft.VisualBasic.DateAndTime.DatePart( _

ByVal Interval As DateInterval, _

ByVal DateValue As DateTime, _

Facultatif ByVal FirstDayOfWeekValue as FirstDayOfWeek = VbSunday, _

ByVal FirstWeekOfYearValue facultatif en tant que FirstWeekOfYear = VbFirstJan1 _

) En tant qu’entier
Consultez la section concernant la fonction DatePart pour plus d'informations.
Microsoft.VisualBasic.DateAndTime.Now CurrentDateTime()
Microsoft.VisualBasic.DateAndTime.Year(DateTime TimeValue) Year()
Microsoft.VisualBasic.DateAndTime.Month(DateTime TimeValue) Month()
Microsoft.VisualBasic.DateAndTime.Day(DateTime TimeValue) Jour()
Microsoft.VisualBasic.DateAndTime.Hour(DateTime TimeValue) Hour()
Microsoft.VisualBasic.DateAndTime.Minute(DateTime TimeValue) Minute()
Microsoft.VisualBasic.DateAndTime.Second(DateTime TimeValue) Second()

Mappage de la méthode System.DateTime (d'instance)

Méthode System.DateTime (instance) Fonction canonique
Égal booléen(DateTime value) = (opérateur)
Jour Jour(this)
Heure Hour(this)
Milliseconde Millisecond(this)
Minute Minute(this)
Mois Month(this)
Deuxième Second(this)
Année Année(this)

Mappage de la méthode System.DateTimeOffset (d'instance)

Mappage indiqué pour les méthodes get sur les propriétés répertoriées.

Mappage de la méthode System.DateTimeOffset (d'instance) Fonction canonique Remarques
Jour Jour(this) Non pris en charge dans SQL Server 2005.
Heure Hour(this) Non pris en charge dans SQL Server 2005.
Milliseconde Millisecond(this) Non pris en charge dans SQL Server 2005.
Minute Minute(this) Non pris en charge dans SQL Server 2005.
Mois Month(this) Non pris en charge dans SQL Server 2005.
Deuxième Second(this) Non pris en charge dans SQL Server 2005.
Année Année(this) Non pris en charge dans SQL Server 2005.

Notes

La méthode Equals retourne true si les objets DateTimeOffset comparés sont égaux ; sinon false. La méthode CompareTo retourne 0, 1 ou -1 selon que l'objet DateTimeOffset comparé est égal, supérieur ou inférieur, respectivement.

Mappage de la méthode System.DateTimeOffset (statique)

Mappage indiqué pour les méthodes get sur les propriétés répertoriées.

Mappage de la méthode System.DateTimeOffset (statique) Fonction canonique Remarques
System.DateTimeOffset.Now() CurrentDateTimeOffset() Non pris en charge dans SQL Server 2005.

Mappage de la méthode System.TimeSpan (d'instance)

Mappage indiqué pour les méthodes get sur les propriétés répertoriées.

Mappage de la méthode System.TimeSpan (d'instance) Fonction canonique Remarques
Heures Hour(this) Non pris en charge dans SQL Server 2005.
Millisecondes Millisecond(this) Non pris en charge dans SQL Server 2005.
Procès-verbaux Minute(this) Non pris en charge dans SQL Server 2005.
Secondes Second(this) Non pris en charge dans SQL Server 2005.

Notes

La méthode Equals retourne true si les objets TimeSpan comparés sont égaux ; sinon false. La méthode CompareTo retourne 0, 1 ou -1 selon que l'objet TimeSpan comparé est égal, supérieur ou inférieur, respectivement.

Fonction DatePart

La fonction DatePart est mappée à l'une des diverses fonctions canoniques, en fonction de la valeur de Interval. Le tableau suivant présente le mappage de la fonction canonique pour les valeurs de Interval prises en charge :

Valeur d'intervalle Fonction canonique
DateInterval.Année Year()
DateInterval.Month Month()
DateInterval.Day Jour()
DateInterval.Hour Hour()
DateInterval.Minute Minute()
DateInterval.Second Second()

Mappage de fonctions mathématiques

Méthode CLR Fonction canonique
System.Decimal.Ceiling(Decimal d) Plafond(d)
System.Decimal.Floor(Decimal d) Floor(d)
System.Decimal.Round(Decimal d) Round(d)
System.Math.Ceiling(Decimal d) Plafond(d)
System.Math.Floor(Decimal d) Floor(d)
System.Math.Round(Decimal d) Round(d)
System.Math.Ceiling(Double a) Plafond(a)
System.Math.Floor(Double a) Floor(a)
System.Math.Round(Double a) Round(a)
System.Math.Round(valeur Double, chiffres Int16) Round(valeur, chiffres)
System.Math.Round(valeur Double, chiffres Int32) Round(valeur, chiffres)
System.Math.Round(valeur Decimal, chiffres Int16) Round(valeur, chiffres)
System.Math.Round(valeur Decimal, chiffres Int32) Round(valeur, chiffres)
System.Math.Abs(valeur Int16) Abs(valeur)
System.Math.Abs(valeur Int32) Abs(valeur)
System.Math.Abs(valeur Int64) Abs(valeur)
System.Math.Abs(valeur Byte) Abs(valeur)
System.Math.Abs(valeur Single) Abs(valeur)
System.Math.Abs(valeur Double) Abs(valeur)
System.Math.Abs(valeur Decimal) Abs(valeur)
System.Math.Truncate(valeur Double, chiffres Int16) Truncate(valeur, chiffres)
System.Math.Truncate(valeur Double, chiffres Int32) Truncate(valeur, chiffres)
System.Math.Truncate(valeur Decimal, chiffres Int16) Truncate(valeur, chiffres)
System.Math.Truncate(valeur Decimal, chiffres Int32) Truncate(valeur, chiffres)
System.Math.Power(valeur Int32, exposant Int64) Power(valeur, exposant)
System.Math.Power(valeur Int32, exposant Double) Power(valeur, exposant)
System.Math.Power(valeur Int32, exposant Decimal) Power(valeur, exposant)
System.Math.Power(valeur Int64, exposant Int64) Power(valeur, exposant)
System.Math.Power(valeur Int64, exposant Double) Power(valeur, exposant)
System.Math.Power(valeur Int64, exposant Decimal) Power(valeur, exposant)
System.Math.Power(valeur Double, exposant Int64) Power(valeur, exposant)
System.Math.Power(valeur Double, exposant Double) Power(valeur, exposant)
System.Math.Power(valeur Double, exposant Decimal) Power(valeur, exposant)
System.Math.Power(valeur Decimal, exposant Int64) Power(valeur, exposant)
System.Math.Power(valeur Decimal, exposant Double) Power(valeur, exposant)
System.Math.Power(valeur Decimal, exposant Decimal) Power(valeur, exposant)

Mappage d'opérateurs de bits

Opérateur de bits Fonction canonique pour les opérandes non booléens Fonction canonique pour les opérandes booléens
Opérateur de bits AND BitWiseAnd op1 ET op2
Opérateur de bits OR BitWiseOr op1 OR op2
Opérateur de bits NOT BitWiseNot NOT(op)
Opérateur de bits XOR BitWiseXor ((op1 AND NOT(op2)) OR (NOT(op1) AND op2))

Autre mappage

Méthode Fonction canonique
Guid.NewGuid() NewGuid()

Voir aussi