检查与实体相关的依赖关系的通用方法
我使用实体框架,需要知道实体是否具有某些依赖项,我应该更改项目的状态,但只有在相关项目不存在依赖项时才能执行此更改。前任:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当在实体类中定义了依赖关系时,此代码才有效。在这种情况下,您不需要通用函数,为什么不在实体类中定义它,例如:
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: