没有调用Breeze BeforeSaveEntity

时间:2015-12-07 17:59:36

标签: breeze

我无法弄清楚为什么在保存新评论时没有调用BeforeSaveEntity()。注释将保存到数据库中,但我在服务器上修改的字段不会更新。未命中BeforeSaveEntity函数中的断点。 SaveChanges()正在运行。

//server controller
public class LeaseRepository : EFContextProvider<LeaseEntities>
{

    public LeaseRepository(IPrincipal user)
    {
        //                
    }

    protected override bool BeforeSaveEntity(EntityInfo entityInfo)
    {
        var entity = entityInfo.Entity;

        if (entity is LeaseComment)
        {
            return BeforeSaveComment(entity as LeaseComment, entityInfo);
        }
        return base.BeforeSaveEntity(entityInfo);
    }

    private bool BeforeSaveComment(LeaseComment c, EntityInfo info)
    {
       // c.Comment = "server comment!";

        if (info.EntityState == EntityState.Added)
        {
            c.UserId = AgentId;// AdName;
            c.CreatedOn = DateTime.UtcNow.ToLocalTime();
        }

        return true;
    }


    private readonly EFContextProvider<LeaseEntities>
        _contextProvider = new EFContextProvider<LeaseEntities>();

    private LeaseEntities Context { get { return _contextProvider.Context; } }

    public string Metadata
    {
        get { return _contextProvider.Metadata(); }
    }

    public SaveResult SaveChanges(JObject saveBundle)
    {
        return _contextProvider.SaveChanges(saveBundle);
    } 
}

1 个答案:

答案 0 :(得分:0)

删除这两个功能修复了它。

public string Metadata
{
    get { return _contextProvider.Metadata(); }
}

public SaveResult SaveChanges(JObject saveBundle)
{
    return _contextProvider.SaveChanges(saveBundle);
} 

我猜测SaveChanges()是个问题。