I tried to translate following C# code
public static class ObjectSetExtensions
{
public static void AddObjects<T>(this ObjectSet<T> objectSet, IEnumerable<T> objects)
{
foreach (var item in objects)
{
objectSet.AddObject(item);
}
}
}
to VB.NET:
Module ObjectSetExtensions
<System.Runtime.CompilerServices.Extension()>
Public Sub AddObjects(Of T)(ByVal objectSet As ObjectSet(Of T), ByVal objects As IEnumerable(Of T))
For Each item In objects
objectSet.AddObject(item)
Next
End Sub
End Module
But I getting an error that says:
Type argument ‘T’ does not satisfy the ‘Class’ constraint for type parameter ‘TEntity’.
What am I missing?
The C# version doesn’t compile either, for the same reason. It should be:
And the VB version is:
Note how in the VB version the constraint is part of the type parameter declaration. For more details, see MSDN.