Entity Framework - Reverse Foreign Key Check

风格不统一 提交于 2019-12-04 18:50:20

You must query metadata and get list of all navigation properties

ObjectSet = context.CreateObjectSet<YourEntityType>();

// Get entity set for current entity type
var entitySet = ObjectSet.EntitySet;
// Get name of the entity's navigation properties
_propertyNames = ((EntityType)entitySet.ElementType).NavigationProperties.Select(p => p.Name).ToArray();

Now you have properties which must be checked before deletion. To check properties you must load those members and you must check if related entity exists. Both will probably require a lot of reflection which will affect performance of your application.

I have to say that your application architecture is horrible. It is like an example: where should EF not be used or how should EF not be used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!