code_junkie

LINQ, Polymorphism, MetaDataMapping, Inheritance Mapper

Nov 11th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. pubic class ConcretePublicObjectOne : IPublicObject{}
  2.  
  3. static void Save<T>(T item)
  4. where T : class, IPublicObject
  5. {
  6. using (DataContext ctx = GetDataContext())
  7. {
  8. Table<T> table = ctx.GetTable<T>();
  9. // for insert...
  10. table.InsertOnSubmit(item);
  11. // for update...
  12. table.Attach(item, true);
  13. // for delete...
  14. table.DeleteOnSubmit(item);
  15.  
  16. ctx.SubmitChanges();
  17.  
  18. }
  19. }
  20.  
  21. Foo foo = new Foo();
  22. Save(foo); // <Foo> is inferred
  23.  
  24. Repository.Save(publicObject)
  25.  
  26. public class Repository {
  27. public void Save(IPublicObject publicObject) {
  28. publicObject.Save();
  29. }
  30. }
  31.  
  32. public interface IPublicObject {
  33. void Save();
  34. }
Add Comment
Please, Sign In to add comment