You can try to create an interface and make your three classes implement this interface; then you can place the restriction in your generic method's declaration on the interface itself. This way:
public interface IObjectWithId
{
ObjectId _id { get; set; }
}
public class insDatalog : IObjectWithId
{
}
public class insUnitLib : IObjectWithId
{
}
public class insSerialNo : IObjectWithId
{
}
public class YourContainerClass
{
public static void DeleteCollectionDataRow<T>(IMongoCollection<T> collection, T t) where T : IObjectWithId
{
collection.DeleteOne(b => b._id.Equals(t._id));
}
}
It also supposes that you correctly implemented the
IEquatable<T>
interface in your
ObjectId
class/struct definition.
You may also rethink your naming scheme as it does not fit very well into the .NET world, but that's more of a "cosmetic" choice remark which you can ignore, eventually.
Hope this helps. Kindly.