C# 如何在服务层或数据访问层中设置ObjectDatasourceStatuseEventArgs?

C# 如何在服务层或数据访问层中设置ObjectDatasourceStatuseEventArgs?,c#,asp.net,objectdatasource,C#,Asp.net,Objectdatasource,我正在使用ObjectDataSource在GridView上执行CRUD操作。删除项目时,我希望能够确保没有违反外键约束,如果是,则使用ObjectDataSource Deleted函数中的ObjectDataSource StatuseEventArgs向表示层中的用户显示消息: protected void ods_Deleted(object sender, ObjectDataSourceStatusEventArgs e) { if (e.Exception != null

我正在使用ObjectDataSource在GridView上执行CRUD操作。删除项目时,我希望能够确保没有违反外键约束,如果是,则使用ObjectDataSource Deleted函数中的ObjectDataSource StatuseEventArgs向表示层中的用户显示消息:

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
    }
}
我认为可以在服务层或数据访问层中检查约束

服务层

数据访问层

我知道,一旦返回到表示层,从服务层函数返回的任何内容都可以在e.ReturnValue中看到,但是是否可以设置ObjectDataSourceStatusEventArgs的其他成员,例如,AffectedRows、Exception、OutputParemters等

// 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
    }
}