Hi there,
For adapter is slightly different, because the persistence logic in adapter is outside the entity. Also you don't need to fetch the entity, you can direct call DeleteEntitiesDirectly. Try this:
public void Delete<T>(object key) where T : IEntity2, new()
{
var entity = new T();
// get pk
var pkField = (EntityField2) GetPrimaryKey((IEntity2)entity);
// create filter
var filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(pkField == key);
using (var adapter = new DataAccessAdapter())
{
adapter.DeleteEntitiesDirectly(typeof(T), filter);
}
return;
}
public static EntityField2 GetPrimaryKey(IEntity2 entity)
{
return (EntityField2) entity.PrimaryKeyFields[0];
}
Usage:
Delete<CustomerEntity>("ALFI");
Note that this code only works if the entity has just 1 PK field. If the entity has a composite key, then you will delete multiple rows, not just one.