public void AddStorageAreaRule(BiblosDS.Library.Common.Objects.DocumentStorageAreaRule StorageAreaRule) { using (Model.BiblosDS2010Entities db = new Model.BiblosDS2010Entities(BiblosDSConnectionString)) { Model.StorageAreaRule entityStorageAreaRule = StorageAreaRule.TryToConvertTo <Model.StorageAreaRule>(db); if (StorageAreaRule.StorageArea != null) { entityStorageAreaRule.IdStorageArea = StorageAreaRule.StorageArea.IdStorageArea; //entityStorageAreaRule.StorageAreaReference.TryToAttach(new Model.StorageArea { IdStorageArea = StorageAreaRule.StorageArea.IdStorageArea }, db); } else { throw new Exception("StorageArea non valorizzato"); } if (StorageAreaRule.Attribute != null) { entityStorageAreaRule.IdAttribute = StorageAreaRule.Attribute.IdAttribute; //entityStorageAreaRule.AttributesReference.TryToAttach(new Model.Attributes { IdAttribute = StorageAreaRule.Attribute.IdAttribute }, db); } else { throw new Exception("Attribute non valorizzato"); } if (StorageAreaRule.RuleOperator != null) { entityStorageAreaRule.IdRuleOperator = StorageAreaRule.RuleOperator.IdRuleOperator; } db.AddToStorageAreaRule(entityStorageAreaRule); db.SaveChanges(); } }