예제 #1
0
        public virtual bool Remove(TTargetEntity item)
        {
            // parameter bindings
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@JoinColumn", RowDataGatewayRegistry <TMappedBy> .GetRowDataGateway().PrimaryKey.Get(mappedBy));
            parameters.Add("@InverseJoinColumn", RowDataGatewayRegistry <TTargetEntity> .GetRowDataGateway().PrimaryKey.Get(item));
            // run command
            NonQueryResult result = SimpleQuery.ExecuteNonQuery(RowDataGatewayRegistry <TMappedBy> .GetRowDataGateway().DatabaseName, CommandType.Text, removeSql, removeParameterTemplates, parameters, false);
            // remove from collection
            bool removedItem = values.Remove(item);

            if (result.RowsAffected == 1)
            {
                if (removedItem)
                {
                    return(true);
                }
                throw new DataException(SR.GetString(SR.ManyToMany_Db_Remove_NonMember));
            }
            else if (result.RowsAffected == 0)
            {
                if (!removedItem)
                {
                    return(false);
                }
                throw new DataException(SR.GetString(SR.ManyToMany_Collection_Remove_NonMember));
            }
            else
            {
                throw new DataException(SR.GetString(SR.ManyToMany_Bad_Delete_Count, new object[] { result.RowsAffected, removedItem ? 1 : 0 }));
            }
        }
예제 #2
0
        public virtual void Clear()
        {
            // parameter bindings
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@JoinColumn", RowDataGatewayRegistry <TMappedBy> .GetRowDataGateway().PrimaryKey.Get(mappedBy));
            // run command
            SimpleQuery.ExecuteNonQuery(RowDataGatewayRegistry <TMappedBy> .GetRowDataGateway().DatabaseName, CommandType.Text, clearSql, clearParameterTemplates, parameters, false);
            // update local collection
            values.Clear();
        }
예제 #3
0
        public virtual void Add(TTargetEntity item)
        {
            if (Contains(item))
            {
                return;
            }
            // parameter bindings
            IDictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@JoinColumn", RowDataGatewayRegistry <TMappedBy> .GetRowDataGateway().PrimaryKey.Get(mappedBy));
            parameters.Add("@InverseJoinColumn", RowDataGatewayRegistry <TTargetEntity> .GetRowDataGateway().PrimaryKey.Get(item));
            // run command
            SimpleQuery.ExecuteNonQuery(RowDataGatewayRegistry <TMappedBy> .GetRowDataGateway().DatabaseName, CommandType.Text, addSql, addParameterTemplates, parameters, false);
            // add to collection
            values.Add(item);
        }