My next issue is that the entities no longer have Ideablade.EntityModel.Entity as a base class
Which means I am having issues with things like cloning.
public static T Clone<T>([NotNull] this T source, int level = 0) where T : Entity
{
if (source == null) throw new ArgumentNullException("source");
var handledEntities = new Dictionary<Entity, Entity>();
return source.InternalClone(level, handledEntities);
}
private static T InternalClone<T>([NotNull] this T source, int level, IDictionary<Entity, Entity> handledEntities) where T: Entity
{
var res = (source as ICloneable).Clone() as T;
handledEntities[source] = res;
if (level > 0)
{
foreach (var pi in source.GetType().GetProperties().Where(pi => pi.CanRead))
{
if (pi.PropertyType.IsChildOf(typeof(RelatedEntityList<>)))
{
var sList = pi.GetValue(source, null) as IList;
var list = pi.GetValue(res, null) as IList;
if (sList != null && list != null)
{
foreach (Entity item in sList)
{
var cItem = handledEntities.ContainsKey(item)
? handledEntities[item]
: item.InternalClone(level - 1, handledEntities);
list.Add(cItem);
}
}
}
else if (pi.CanWrite && pi.PropertyType.IsSubclassOf(typeof(Entity)))
{
var sInstance = pi.GetValue(source, null) as Entity;
if (sInstance != null)
{
var clonedEntity = handledEntities.ContainsKey(sInstance)
? handledEntities[sInstance]
: sInstance.InternalClone(level - 1, handledEntities);
pi.SetValue(res, clonedEntity, null);
}
}
}
}
return res;
}
Do you have any advice on how I can now hande this?