C
Cowboy \(Gregory A. Beamer\)
Just wanted to ping this off of someone and what better place to do it than
here.
I have the following:
public void Delete(T entity)
{
Type type = entity.GetType();
//TODO: Can make this dynamic for flexibility
string property = "IsDeleted";
PropertyInfo propertyInfo = type.GetProperty(property);
if (propertyInfo == null)
{
Destroy(entity);
}
else
{
using (System.Data.Linq.DataContext context =
_dataContextFactory.Context)
{
Table<T> table = context.GetTable<T>();
//TODO: Figure out why .Attach() is not working and stop
grabbing object
entity = table.First(s => s == entity);
MethodInfo methodInfo = propertyInfo.GetSetMethod();
object[] o = { true };
methodInfo.Invoke(entity, o);
context.SubmitChanges();
}
}
}
It works, but there must be an easier way to save than to find the object
prior to making changes. The destroy method works fine,. but having to
search for the object prior to Submitting changes seems rather cheese to me.
Thoughts?
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
here.
I have the following:
public void Delete(T entity)
{
Type type = entity.GetType();
//TODO: Can make this dynamic for flexibility
string property = "IsDeleted";
PropertyInfo propertyInfo = type.GetProperty(property);
if (propertyInfo == null)
{
Destroy(entity);
}
else
{
using (System.Data.Linq.DataContext context =
_dataContextFactory.Context)
{
Table<T> table = context.GetTable<T>();
//TODO: Figure out why .Attach() is not working and stop
grabbing object
entity = table.First(s => s == entity);
MethodInfo methodInfo = propertyInfo.GetSetMethod();
object[] o = { true };
methodInfo.Invoke(entity, o);
context.SubmitChanges();
}
}
}
It works, but there must be an easier way to save than to find the object
prior to making changes. The destroy method works fine,. but having to
search for the object prior to Submitting changes seems rather cheese to me.
Thoughts?
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************