public object ResetResource(object resource)
        {
            CustomUtils.CheckArgumentNotNull(resource, "resource");

            CustomEntityType entityType;

            if (!MetadataWorkspace.TryGetEntityType(resource.GetType(), out entityType))
            {
                throw new NotImplementedException(String.Format(
                                                      "ResetResource() is implemented only for entity types. " +
                                                      "The given object '{0}' is not a valid entity."
                                                      ));
            }

            foreach (var property in entityType.Propeties)
            {
                if (!property.IsReadOnly && !property.IsPrimaryKey && null == property.ForeignKeyConstraint)
                {
                    object defaultValue;
                    if (property.IsNullable)
                    {
                        defaultValue = null;
                    }
                    else
                    {
                        defaultValue = Activator.CreateInstance(property.ClrType);
                    }

                    property.SetValue(resource, defaultValue);
                }
            }

            return(resource);
        }
        private bool TryGetEntityMember(
            object targetResource,
            string memberName,
            out CustomMemberType entityMember
            )
        {
            entityMember = null;

            CustomEntityType entityType;

            if (!MetadataWorkspace.TryGetEntityType(targetResource.GetType(), out entityType))
            {
                return(false);
            }

            entityMember = entityType.Members
                           .Where(m => m.Name.Equals(memberName))
                           .Select(m => m)
                           .SingleOrDefault();

            return(null != entityMember);
        }