Cloning of nhibernate class Objects

347 views
Skip to first unread message

Kolli Ayyappa

unread,
Aug 23, 2011, 5:14:41 PM8/23/11
to nhusers
Hi,

I am trying to close one object to another object of nhibernate class.

For eg:
I have AutoID class and assocation as one object
I plan to clone to another object Cert, now all common properties
need to copy to Cert object with assocation values

I am looking, is there way nhibernate providing this feature or any
thoughts


Thanks,
Ayyappa kolli

Ramon Smits

unread,
Aug 24, 2011, 4:22:13 AM8/24/11
to nhu...@googlegroups.com
No, NHibernate does not provide cloning as it has no knowledge on how
to clone relations as a deep or shallow copy.

Just implement IClonable and implement the method. It really is
nothing special when all your objects implement it this way.

If you really have a shitload of properties then you could for exampe
use AutoMapper to perform the cloning but I would advise to just do
the mapping by hand.

Example:

public class CloneMePlease : ICloneable
{
public int Id { get; protected set; }
public string X { get; set; }
public string Y { get; set; }
public string Z { get; set; }

public CloneMePlease Clone()
{
return new CloneMePlease
{
X = X,
Y = Y,
Z = Z
};
}

object ICloneable.Clone()
{
return Clone();
}
}


Hope this helps.

--
Ramon

> --
> You received this message because you are subscribed to the Google Groups "nhusers" group.
> To post to this group, send email to nhu...@googlegroups.com.
> To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
>
>

--
Ramon

Reply all
Reply to author
Forward
0 new messages