0

我已将现有项目更改为首先使用 EF5 和代码。它使用依赖于旧 ObjectContext 的存储库类。为了保持存储库实现相同,我在 DBContext 上创建了一个属性,该属性将返回一个 ObjectContext:

public ObjectContext ObjectContext()
{
    return (this as IObjectContextAdapter).ObjectContext;
}

问题是在此之后实体在 ObjectContext 上不可用,因此以下代码失败:

string GetSetName<T>() {
    var entitySetProperty =
    _context.GetType().GetProperties()
       .Single(p => p.PropertyType.IsGenericType && typeof(IQueryable<>)
       .MakeGenericType(typeof(T)).IsAssignableFrom(p.PropertyType));

    return entitySetProperty.Name;
}

原始 DBContext 在转换为 ObjectContext 之前具有所有可用的实体,但由于 ObjectContext 类没有我的实体的属性,我该如何访问它们?

4

0 回答 0