public static void Delete<T>(object primaryKey) where T : class { using (MainDataContext context = new MainDataContext()) { MetaDataMember id = context.Mapping.GetTable(typeof(T)).RowType.IdentityMembers[0]; ParameterExpression parameter = Expression.Parameter(typeof(T), "item"); T entity = context.GetTable<T>().Single<T>(Expression.Lambda<Func<T, bool>>(Expression.Equal(Expression.Property(parameter, id.Member.Name), Expression.Constant(primaryKey)), parameter)); context.GetTable<T>().DeleteOnSubmit(entity); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)