CUD 方法不会触发

发布于 2024-09-06 17:08:05 字数 1316 浏览 3 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那小子欠揍 2024-09-13 17:08:05

我错误地覆盖了 Submit 方法。

I have overrode the Submit method by mistake.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文