//Repository Method
public void Delete(int id)
{
using (var scope = new UnitOfWork(_container))
{
var entity = AuthorService.GetById(id);
scope.Container.Authors.DeleteObject(entity);
}
}
Ninject binding
public class LibraryManagerInjectModule : NinjectModule
{
public override void Load()
{
Bind<LibManagerContainer>().To<LibManagerContainer>().InThreadScope();
}
}
//Author Service Class
public static class AuthorService
{
private static LibManagerContainer Container
{
get { return MF.MF.Get<LibManagerContainer>(); }
}
public static Author GetById(int id)
{
using (var scope = new UnitOfWork(Container))
{
return Container.Authors.SingleOrDefault(x => x.Id == id);
}
}
public static Author GetByName(String name)
{
using (var scope = new UnitOfWork(Container))
{
return Container.Authors.SingleOrDefault(x => x.Name == name);
}
}
}
Using this code i m not able to delete the entity from database. it show me an error that entity not belong to same object state manager but i create the libContainer object inThreadscope but never able to delete the entity.