The simplest solution in many cases will be to serialize/deserialze the object to do an easy clone of it. Which serialize/clone method you use is up to you. This question has a bunch of suggestions in that regard.
I like to use Newtonsoft JSON.NET for serialization because it is super-easy to use, has minimal requirements (e.g. no compiler attributes required) and I already use it for other stuff in my projects. Depending on your use case (e.g. detaching a LINQ/SQL entity to use within a UI model) you may want to wipe off the database IDs. An easy way to do that is to pass a custom DefaultContractResolver class to JSON.NET that will exclude the ID properties:
return JsonConvert.SerializeObject(oModel, new JsonSerializerSettings() { ContractResolver = new DNSConfigurationModel.DNSConfigSerializer() });
/// <summary>
/// Helper class to ensure that we do not serialize the domainAdvancedDNS child objects
/// (we will create our own child collections for serialization). We also suppress serialization of the key ID's.
/// </summary>
public class DNSConfigSerializer : DefaultContractResolver
{
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
return (from p in properties
where p.PropertyName != "DomainAdvancedDNS" &&
p.PropertyName != "domainAdvancedDNSSRVs" &&
!(p.DeclaringType.Name == "DomainAdvancedDN" && p.PropertyName == "domainAdvancedDNSConfigID") &&
p.PropertyName != "DomainAdvancedDNSID" &&
p.PropertyName != "domainAdvancedDNSSRVID"
select p).ToList();
}
}