如何在服务或数据访问层中设置ObjectDataSourceStatusEventArgs?

时间:2013-04-03 17:52:05

标签: c# asp.net objectdatasource

我正在使用ObjectDataSourceGridView上执行CRUD操作。删除项目时,我希望能够确保没有违反外键约束,如果是,则使用{{1}中的ObjectDataSourceStatusEventArgs在表示层中向用户显示消息功能:

ObjectDataSource Deleted

我认为可以在服务层或数据访问层中检查约束。

服务层

protected void ods_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
{
    if (e.Exception != null)
    {
        // Display message that was set in either the service or data access layer
    }
}

数据访问层

// This is the DeleteMethod used by the ObjectDataSource
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public virtual bool Remove(Entity entity)
{
    bool CanDelete = functionToSeeIfAnythingIsUsingThisKey(entity.ID);
    if (CanDelete)
    {
        _repository.Remove(entity);
        return true;
    }
    else
    {
        // would like to populate ObjectDataSourceStatusEventArgs that are sent
        // back to the ObjectDataSource onDeleted function in Presentation layer
        return false;
    }
}

我知道从服务层函数返回的任何内容都可以在public virtual void Remove(Entity entity) { _session = NHibernateSessionProvider.GetSession(); try { using (ITransaction transaction = _session.BeginTransaction()) { _session.Delete(entity); transaction.Commit(); } } catch { // database will throw an error if the constraint check fails, // which is caught here } } 中看到一次回到表示层,但是是否可以设置e.ReturnValue的其他成员(即AffectedRows,异常,OutputParemters等)?

0 个答案:

没有答案