public void AddStorageRule(BiblosDS.Library.Common.Objects.DocumentStorageRule StorageRule) { using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString)) { Model.StorageRule entityStorageRule = StorageRule.TryToConvertTo <Model.StorageRule>(db); if (StorageRule.Storage != null) { entityStorageRule.IdStorage = StorageRule.Storage.IdStorage; //entityStorageRule.StorageReference.TryToAttach(new Model.Storage { IdStorage = StorageRule.Storage.IdStorage }, db); } else { throw new Exception("Storage non valorizzato"); } if (StorageRule.Attribute != null) { entityStorageRule.IdAttribute = StorageRule.Attribute.IdAttribute; //entityStorageRule.AttributesReference.TryToAttach(new Model.Attributes { IdAttribute = StorageRule.Attribute.IdAttribute }, db); } else { throw new Exception("Attribute non valorizzato"); } if (StorageRule.RuleOperator != null) { entityStorageRule.IdRuleOperator = StorageRule.RuleOperator.IdRuleOperator; } db.AddToStorageRule(entityStorageRule); db.SaveChanges(); } }