DAL 更新方法的通用方法签名

发布于 2024-12-02 07:15:28 字数 474 浏览 0 评论 0原文

我正在使用一个多用途存储过程,它可以为声明或保单执行插入或更新。我只想创建一个 DAL 方法来调用此更新/插入。

我有一个 IBaseAdjustment,其中包含声明对象和策略对象的所有属性。 Claim是Policy的子集,因此它将继承Policy。如果没有传入任何值,存储过程将设置为默认值,因此我尽可能使用可为空的属性。

我被困在更新调用的方法签名上。我

    public bool UpdateManualAdjustmentTransaction<T>() where T : IBaseAdjustment
    {}

只是不确定现在如何设置对我的实体的引用来设置参数,我本以为它会是类似的东西,

IbaseAdjustment _adjustment = T as IBaseAdjustment; 

但它不喜欢那样。建议? '谢谢

I am working with a multi-purpose Stored Procedure that does either an insert or update for either Claim or Policy. I would like to only create one DAL method to call this update/insert.

I have a IBaseAdjustment that contains all of the properties of both a Claim Object and a Policy Object. Claim is a subset of Policy so It will inherit Policy. The stored procedure is set up to default to values if none are passed in so therefore I am using nullable properties where possible.

I am stuck on the method signature for the Update call. I have

    public bool UpdateManualAdjustmentTransaction<T>() where T : IBaseAdjustment
    {}

I am just not sure how to set the reference to my entity now to set the parameters I would have thought it would be something like

IbaseAdjustment _adjustment = T as IBaseAdjustment; 

but it does not like that. Suggestions?
'Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

眼眸里的那抹悲凉 2024-12-09 07:15:28

如果您只是要使用该接口,则根本不需要将其作为通用方法:

public bool UpdateManualAdjustmentTransaction(IBaseAdjustment baseAdjustment)
{
     // use baseAdjustment
}

这将允许您将任一实体直接传递给此方法。

If you're just going to use the interface, there is no need for this to be a generic method at all:

public bool UpdateManualAdjustmentTransaction(IBaseAdjustment baseAdjustment)
{
     // use baseAdjustment
}

This will let you pass either of your entities to this method directly.

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