you can use :
void IDepartmentDataSource.Delete(Entry entry)
{
Entries.Remove(entry);
}
but may be,
using a repository like below could be better
(a repository that encapsulate every CRUD EF operation)
i would make it in 2 steps :
public class DepartmentDb : DbContext
{
public DepartmentDb() : base("DefaultConnection")
{
}
public DbSet<User> Users { get; set; }
public DbSet<Department> Departments { get; set; }
public DbSet<Entry> Entries { get; set; }
}
public class DepartmentRepository: IDisposable
{
protected bool isDisposed = false;
private DepartmentDb Context { get; set; }
public IQueryable<user> Users { get { return Context.Users; } }
public IQueryable<department> Departments { get { return Context.Departments; } }
public IQueryable<entry> Entries { get { return Context.Entries; } }
public DepartmentRepository()
{
Context = new DepartmentDb();
}
public int Insert(User item)
{
Context.Users.Add(item);
return Context.SaveChanges();
}
public int Update(User item)
{
Context.Entry<user>(item).State = EntityState.Modified;
return Context.SaveChanges();
}
public int Delete(User item)
{
Context.Users.Remove(item);
return Context.SaveChanges();
}
protected virtual void Dispose(bool disposing)
{
if (isDisposed)
return;
if (disposing)
{
if (this.Context != null)
{
this.Context.Dispose();
this.Context = null;
}
}
isDisposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
usage :
using(var repo = new DepartmentRepository())
{
var u = new User(){Name="Jack"};
var repo.Insert(u);
u.Name = "Jim";
repo.Update(u);
repo.Delete(u);
}
if you want to read more look for "repository pattern" there are several versions of it
UPDATE :
if you want to write less code ;)
you can write
public interface IDepRepoEntity
{
}
public partial class User : IDepRepoEntity {}
public partial class Department: IDepRepoEntity {}
public partial class Entry: IDepRepoEntity {}
than in your repository :
public int Insert<T>(T item) where T : IDepRepoEntity
{
Context.Set<T>.Add(item);
return Context.SaveChanges();
}
public int Update<T>(T item) where T : IDepRepoEntity
{
Context.Entry<T>(item).State = EntityState.Modified;
return Context.SaveChanges();
}
public int Delete<T>(T item) where T : IDepRepoEntity
{
Context.Set<T>.Remove(item);
return Context.SaveChanges();
}