I have a POCO entity as follows:
public class Entity {
public int Id { get; set; }
public int? OtherEntityId { get; set; }
public virtual OtherEntity OtherEntity { get; set; }
}
The code-first configuration is as follows:
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);
I'd like to be able to retrieve the database generated option & FK properties at runtime. For example, I can dynamically retrieve the primary key property like so:
var keyProperties = objectContext.CreateObjectSet<Entity>()
.EntitySet
.ElementType
.KeyMembers
.Select(km => typeof(Entity).GetProperty(km.Name));
.ToList()
How can I do this (I am using EF 4.3.1)?