Skip to content

Instantly share code, notes, and snippets.

@davybrion
Created September 10, 2012 18:41
Show Gist options
  • Save davybrion/3692824 to your computer and use it in GitHub Desktop.
Save davybrion/3692824 to your computer and use it in GitHub Desktop.
code snippets for "Hey Microsoft, Our Databases Aren’t Services!" post
// Implements application logic using the ChinookEntities context.
// TODO: Add your application logic to these methods or in additional methods.
// TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
// Also consider adding roles to restrict access as appropriate.
// [RequiresAuthentication]
[EnableClientAccess()]
public class AlbumService : LinqToEntitiesDomainService<ChinookEntities>
{
// TODO: Consider
// 1. Adding parameters to this method and constraining returned results, and/or
// 2. Adding query methods taking different parameters.
public IQueryable<Album> GetAlbum()
{
return this.ObjectContext.Album;
}
}
public void InsertAlbum(Album album)
{
this.ObjectContext.AddToAlbum(album);
}
public void UpdateAlbum(Album currentAlbum)
{
if ((currentAlbum.EntityState == EntityState.Detached))
{
this.ObjectContext.AttachAsModified(currentAlbum, this.ChangeSet.GetOriginal(currentAlbum));
}
}
public void DeleteAlbum(Album album)
{
if ((album.EntityState == EntityState.Detached))
{
this.ObjectContext.Attach(album);
}
this.ObjectContext.DeleteObject(album);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment