Clone Aggregates

Nov 26, 2010 at 1:00 PM

Hi,

If I have an aggregate in Entity Framework (with a root entity and some entity relations of any depth) could this be copied as a "clone"-like functionality in an easy way?

Thanks in advance,

Kings.

Coordinator
Nov 26, 2010 at 1:47 PM

Hi,

For the moment it's like this:

var c = new Class();
c.InjectFrom(o);
c.C2 = new Class2();
c.C2.InjectFrom(o.C2);

But I think it should be possible to create a CloneInjection, I might try to do this

Nov 26, 2010 at 2:13 PM

Ok,

Thank you very much again.

Coordinator
Nov 26, 2010 at 7:22 PM

here's a injection that I came up with:

public class CloneInjection : LoopValueInjection
        {
            protected override bool AllowSetValue(object value)
            {
                return value != null;
            }

            protected override object SetValue(object sourcePropertyValue)
            {
                if (SourcePropType.IsValueType || SourcePropType == typeof(string))
                    return sourcePropertyValue;

                return Activator.CreateInstance(SourcePropType).InjectFrom<CloneInjection>(sourcePropertyValue);
            }
        }

use it like this:

var f1 = new Foo();
f1.InjectFrom<CloneInjection>(f);

it doesn't works yet with IEnumerables and Arrays but I will try to do this in the future