检查与实体相关的依赖关系的通用方法

发布于 2024-12-25 05:39:46 字数 367 浏览 3 评论 0原文

我使用实体框架,需要知道实体是否具有某些依赖项,我应该更改项目的状态,但只有在相关项目不存在依赖项时才能执行此更改。前任:

 public class DependencyServices<TEntity> where TEntity: Entity
   {
       public bool VerifyDependencies(TEntity entity)
       {
          if(entity.Dependency != null)
           {
               return true;
           }

           return false;
       }

   }

I use the Entity Framework and need to know if an entity has some dependencies that I should make a change of status on an item, but this change can only be performed if there is no dependence that related item. ex:

 public class DependencyServices<TEntity> where TEntity: Entity
   {
       public bool VerifyDependencies(TEntity entity)
       {
          if(entity.Dependency != null)
           {
               return true;
           }

           return false;
       }

   }

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

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

发布评论

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

评论(1

绝情姑娘 2025-01-01 05:39:46

仅当在实体类中定义了依赖关系时,此代码才有效。在这种情况下,您不需要通用函数,为什么不在实体类中定义它,例如:

public bool HasDependencies
{
   get
   {
      return Dependency !=null;
   }
}

This code only works if Dependency is defined in Entity class. In that case you don't need a generic function, why not define it in Entity class like:

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