CUD 方法不会触发
我正在尝试将 RIA 服务与存储库模式一起使用,每个 CRUD 操作都完美运行,直到我实现存储库。现在只有查询和提交方法有效。我尝试了带有和不带有查询、插入、更新和删除属性的方法。
有人知道问题是什么吗?
[LinqToEntitiesDomainServiceDescriptionProvider(typeof(MyEntityModelContainer))]
[EnableClientAccess()]
public class MyService : DomainService
{
internal IUnitOfWork ObjectContext { get; private set; }
public MyService(IUnitOfWork context)
{
this.ObjectContext = context;
}
public IQueryable<Employee> GetEmployees()
{
return this.ObjectContext.BusinessEntities.OfType<Employee>();
}
public void InsertEmployee(Employee employee)
{
this.ObjectContext.BusinessEntities.AddObject(employee);
}
public void UpdateEmployee(Employee currentEmployee)
{
this.ObjectContext.BusinessEntities.AttachAsModified(currentEmployee, this.ChangeSet.GetOriginal(currentEmployee));
}
public void DeleteEmployee(Employee employee)
{
if( (employee.EntityState == EntityState.Detached) )
{
this.ObjectContext.BusinessEntities.Attach(employee);
}
this.ObjectContext.BusinessEntities.DeleteObject(employee);
}
public override bool Submit(ChangeSet changeSet)
{
this.ObjectContext.Commit();
return true;
}
}
I'm trying to use RIA Services with Repository pattern, Every CRUD operations worked perfectly until I implemented the repositories. Now only query and Submit methods are working. I tried the methods both with and without Query, Insert, Update and Delete attributes.
Does anybody know what the problem is?
[LinqToEntitiesDomainServiceDescriptionProvider(typeof(MyEntityModelContainer))]
[EnableClientAccess()]
public class MyService : DomainService
{
internal IUnitOfWork ObjectContext { get; private set; }
public MyService(IUnitOfWork context)
{
this.ObjectContext = context;
}
public IQueryable<Employee> GetEmployees()
{
return this.ObjectContext.BusinessEntities.OfType<Employee>();
}
public void InsertEmployee(Employee employee)
{
this.ObjectContext.BusinessEntities.AddObject(employee);
}
public void UpdateEmployee(Employee currentEmployee)
{
this.ObjectContext.BusinessEntities.AttachAsModified(currentEmployee, this.ChangeSet.GetOriginal(currentEmployee));
}
public void DeleteEmployee(Employee employee)
{
if( (employee.EntityState == EntityState.Detached) )
{
this.ObjectContext.BusinessEntities.Attach(employee);
}
this.ObjectContext.BusinessEntities.DeleteObject(employee);
}
public override bool Submit(ChangeSet changeSet)
{
this.ObjectContext.Commit();
return true;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我错误地覆盖了 Submit 方法。
I have overrode the Submit method by mistake.