I am getting error to convert T to Entity
public T Add(T entity)
{
CAFMEntities db = new CAFMEntities();
db.TabMasters.AddObject((TabMaster)entity);
db.SaveChanges();
return entity;
}
It is giving me an error:
Cannot convert type ‘T’ to ‘CAFM.Data.EntityModel.TabMaster’
Thanks.
Well, how do you want the conversion to apply? Where is T declared? You may be able to change it so that you have:
at which point you don’t need the cast. Or if you can’t constrain
T, you can use:An alternative is:
although personally I’m not as fond of that – I prefer the stricter checking of the cast.