我試圖在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