public void Remove(T obj)
        {
            String sqlCommand;

            SqlParameter[] parameters;

            sqlCommand = @"DELETE FROM " + RelationshipTableName
                         + " WHERE " + ChildKeyColumnName + " = @" + ChildKeyColumnName
                         + " AND " + ParentKeyColumnName + " = @" + ParentKeyColumnName;

            parameters = new SqlParameter[]
            {
                new SqlParameter(ParentKeyColumnName
                                 , SqlBuilderServices.GetDBTypeFromSystemType(_parentObject.ActiveRecordMap.PrimaryKeyColumnMap.Property.PropertyType)
                                 , _parentObject.Id),

                new SqlParameter(ChildKeyColumnName
                                 , SqlBuilderServices.GetDBTypeFromSystemType(ActiveRecord <T> .GetMap().PrimaryKeyColumnMap.Property.PropertyType)
                                 , obj.Id)
            };

            //Execute Delete Command
            ActiveRecordSession.GetSession().DatabaseServices.ExecuteNonQuery(sqlCommand, parameters);

            ObjectList.Remove(obj);
            _retrivedObjects.Remove(obj.Id);
        }
 public static void CreateSession(IDbProvider dbProvider)
 {
     lock (_ActiveRecordSessionLock)
     {
         if (_instance == null)
         {
             _instance = new ActiveRecordSession(dbProvider);
         }
     }
 }
        public override void Save()
        {
            String where;
            SqlParameter[] parameters;

            foreach (T obj in ObjectList)
            {
                //Set each child's foreign key to the parent's primary key
                if (obj.Version < _parentObject.Version)
                {
                    obj.Save();
                }

                //Insert relationship row for newly added/created child objects
                if (!_retrivedObjects.Contains(obj.Id))
                {
                    string command = @"INSERT INTO " + RelationshipTableName
                                     + "(" + ParentKeyColumnName + "," + ChildKeyColumnName + ")"
                                     + " VALUES(@" + ParentKeyColumnName + ", @" + ChildKeyColumnName + ")";

                    parameters = new SqlParameter[]
                    {
                        new SqlParameter(ParentKeyColumnName
                                         , SqlBuilderServices.GetDBTypeFromSystemType(_parentObject.ActiveRecordMap.PrimaryKeyColumnMap.Property.PropertyType)
                                         , _parentObject.Id),

                        new SqlParameter(ChildKeyColumnName
                                         , SqlBuilderServices.GetDBTypeFromSystemType(ActiveRecord <T> .GetMap().PrimaryKeyColumnMap.Property.PropertyType)
                                         , obj.Id)
                    };

                    //Execute Insert Command
                    ActiveRecordSession.GetSession().DatabaseServices.ExecuteNonQuery(command, parameters);

                    _retrivedObjects.Add(obj.Id);
                }
            }
        }