我试图在Entities
类中为DbSet
属性指定static List<PropertyInfo>
。Linq .Where(type = typeof(xxx))的比较始终为假
但是,当代码运行时,List是空的,因为.Where(x => x.PropertyType == typeof(DbSet))
总是返回false。
我尝试了.Where(...)
方法中的多个变体,如typeof(DbSet<>)
,Equals(...)
,.UnderlyingSystemType
等,但没有任何作用。
为什么.Where(...)
总是在我的情况下返回false?
我的代码:
public partial class Entities : DbContext
{
//constructor is omitted
public static List<PropertyInfo> info = typeof(Entities).getProperties().Where(x => x.PropertyType == typeof(DbSet)).ToList();
public virtual DbSet<NotRelevant> NotRelevant { get; set; }
//further DbSet<XXXX> properties are omitted....
}
'DbSet'!='DbSet'...我会说这就是问题 –
@ClaudioRedi是的,这是问题。网上有资源可以阅读差异吗? – Tom