Created
September 25, 2009 15:02
-
-
Save tncbbthositg/193601 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class EntityItemExtension | |
{ | |
public static TEntity GetById<TEntity>(this IEnumerable<TEntity> source, int id) | |
where TEntity : class, IEntityItem | |
{ | |
return source.First(e => e.Id.Equals(id)); | |
} | |
public static void Save<TEntity>(this TEntity entity) | |
where TEntity : class, IEntityItem | |
{ | |
Table<TEntity> da = PALDataContext.Context.GetTable<TEntity>(); | |
if (entity.Id > 0) | |
da.Attach(entity, true); | |
else | |
da.InsertOnSubmit(entity); | |
da.Context.SubmitChanges(); | |
} | |
public static void Delete<TEntity>(this TEntity entity) | |
where TEntity : class, IEntityItem | |
{ | |
Table<TEntity> da = PALDataContext.Context.GetTable<TEntity>(); | |
da.Attach(entity); | |
da.DeleteOnSubmit(entity); | |
da.Context.SubmitChanges(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment