I have property A
with a ICollection<A>
if I then make an alias like (T is A)
public virtual T Children
{
get
{
return ICollection<T>;
}
set
{
ICollection<T> = value;
}
}
where is the lookup of entities executed? In code or in SQL Server? How does EF like this solution?
Added: The problem... I have a 10year old legacy system with nHibernate(ver 1.X) and c#. It inherits in a chain to have the classes written to database have certain markup. Everyone inherits a set of groundproperties and the some have have a child /parent relationship has (from legacy code)
public abstract class GroundpropertiesTreeBaseEntity<T> : GroundpropertiesEntity
{
[JsonIgnore]
public virtual T Parent { get; set; }
public virtual IList<T> Children { get; set; }
}
If I look in the database what has been generated every one has a parentID to itselfs entity.
But if I try this in EF the problem will be how T Parent foreign key will be named. It expect it to be type T and then _Id and not anything else. You can write alias for this but it will not solve the Id problem since you cant write [Foreignkey(GetType(T)+"_Id"]. If I cant get a solution to make this work have to really somereally insane solution which I rather not do since it would me to rewrite the entire system since so many methods using this syntax for it classes.
I hope this cleared this up.
I solved this by writing [Foreignkey("ThegenericKeyName")] in everyclass. Not a good or beautiful solution to handle a generic baseclass but it solves the problem .
inherit the attribute foreignkey class and then add _Id to the name of the property that it was placed on and then send it to foreignkey attribute baseclass name property. But I was out of time so I went for the first solution.