0
我有一個POCO實體如下:實體框架:如何動態檢索列和外鍵列DatabaseGeneratedOptions導航性能?
public class Entity {
public int Id { get; set; }
public int? OtherEntityId { get; set; }
public virtual OtherEntity OtherEntity { get; set; }
}
代碼優先配置如下:
conf.HasKey(e => e.Id).ToTable("entities");
conf.Property(e => e.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
conf.HasOptional(e => e.OtherEntity).WithMany().HasForeignKey(e => e.OtherEntityId);
我想能夠檢索數據庫生成選項& FK特性在運行。例如,我可以動態檢索主鍵屬性,如下所示:
var keyProperties = objectContext.CreateObjectSet<Entity>()
.EntitySet
.ElementType
.KeyMembers
.Select(km => typeof(Entity).GetProperty(km.Name));
.ToList()
我該怎麼做(我正在使用EF 4.3.1)?