So I have to import a table from another database. The table is self referencing using it's own key, but I can't trust the key, especially since the table I'm importing into will be for multiple datasets.
I'm using entity framework and code first fluent api, but having a bugger of a time finding a workaround to this issue.
Here is my POCO class (simplified to only the data points needed):
public class Person
{
public virtual int Id { get; set; }
public virtual int personid { get; set; }
public virtual int? parentid { get; set; }
public virtual Person parent { get; set; }
public virtual ICollection<Person> children { get; set; }
}
This is would be a simple self referencing table, if I could use Id, but I have to use personid. I have setup the idea of the fluent api that I need here, but EF keeps looking at Id.
modelBuilder.Entity<Person>()
.HasOptional(p => p.parent)
.WithMany(p => p.children)
.HasForeignKey(p => p.parentid)
.WillCascadeOnDelete(false);
Any workaround ways to fill the collection using the personid as a Unique Constraint (that is not yet implemented in EF6.1.2)?
I am also using Asp.NetBoilerplate, so some control over my entities, repositories, etc. are possible, but not recommended. I.e. 'Id' is assumed to be the Primary Key for any and all tables.