/// <summary>
 /// Create a new RuleBook object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="changeId">Initial value of the ChangeId property.</param>
 /// <param name="effectiveDate">Initial value of the EffectiveDate property.</param>
 /// <param name="active">Initial value of the Active property.</param>
 public static RuleBook CreateRuleBook(global::System.Int32 id, global::System.String name, global::System.Guid changeId, global::System.DateTime effectiveDate, global::System.Boolean active)
 {
     RuleBook ruleBook = new RuleBook();
     ruleBook.Id = id;
     ruleBook.Name = name;
     ruleBook.ChangeId = changeId;
     ruleBook.EffectiveDate = effectiveDate;
     ruleBook.Active = active;
     return ruleBook;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the RuleBooks EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRuleBooks(RuleBook ruleBook)
 {
     base.AddObject("RuleBooks", ruleBook);
 }
        public void SaveRuleBook(RuleBookModel model)
        {
            var id = Convert.ToInt32(model.Id);
            var ruleBook = Db.RuleBooks.FirstOrDefault(p => p.Id == id);
            if (ruleBook == null)
            {
                ruleBook = new RuleBook()
                                      {
                                          EffectiveDate = EffectiveDate,
                                          Active = true,
                                          ChangeId = Guid.NewGuid(),
                                      };

                Db.RuleBooks.AddObject(ruleBook);
            }
            ruleBook.BaseChangeId = model.BaseChangeId;
            ruleBook.Name = model.Name;
            ruleBook.Active = model.Active;
            Db.SaveChanges();
        }
 private static RuleBookModel RateBook(RuleBook p,RuleBookModel[] derived)
 {
     return new RuleBookModel(p.Id.ToString(), p.Name, p.ChangeId.ToString(), p.EffectiveDate)
     {
         Active = p.Active,
         BaseChangeId = p.BaseChangeId,
         DerivedRuleBooks = derived
     };
 }
 public RuleBookModel[] GetDerivedRuleBooks(RuleBook rb)
 {
     return Db.RuleBooks.Where(p => p.BaseChangeId == rb.ChangeId).ToArray().Select(p=>RateBook(p,GetDerivedRuleBooks(p))).ToArray();
 }