Na verdade eu estou utilizando o NHibernate(Castle ActiveRecord).
Vamos especificar mais então. Cliente NxM Ocorrencias.
[code][HasAndBelongsToMany(typeof(Customer), Table = “CLIENTE_OCORRENCIA”, ColumnKey = “CD_OCORRENCIA”
, ColumnRef = “CD_CNPJ”, RelationType = RelationType.Set, Cascade = ManyRelationCascadeEnum.SaveUpdate)]
public virtual ICollection Customers
{
get { return _customers; }
set { _customers = value; }
}
public virtual void AddOccurences(long[] cnpj)
{
Customer[] customers = Customer.FindBy(cnpj);
foreach (Customer cust in customers)
{
_customers.Add(cust);
}
}[/code]
[HasAndBelongsToMany(typeof(Occurrence), Table = "CLIENTE_OCORRENCIA", ColumnKey = "CD_CNPJ",
ColumnRef = "CD_OCORRENCIA", Lazy = true, Inverse = true, RelationType = RelationType.Set, Cascade = ManyRelationCascadeEnum.SaveUpdate)]
public virtual ICollection<Occurrence> Occurrences
{
get { return _occurrences; }
set { _occurrences = value; }
}
Dessa forma eu busco todos os clientes para terem aquela ocorrênca, pois isso é feito em lote, então se eu selecionar três clientes para a ocorrência 1, esses três clientes deve ter essa ocorrência.
Abaixo fica o log gerado pelo log4net:
[quote]2009-11-20 13:43:14,296 [8] DEBUG NHibernate.SQL - SELECT this_.CD_CNPJ as CD1_11_0_, this_.NM_CLIENTE as NM2_11_0_, this_.DS_ENDERECO as DS3_11_0_, this_.DS_CIDADE as DS4_11_0_, this_.DS_UF as DS5_11_0_, this_.DS_EMAIL as DS6_11_0_, this_.DS_FONE as DS7_11_0_, this_.DS_CONTATO as DS8_11_0_, this_.ID_STATUS as ID9_11_0_ FROM CLIENTE this_ WHERE this_.CD_CNPJ in (?p0, ?p1, ?p2, ?p3);?p0 = 68768769876876, ?p1 = 80809808090909, ?p2 = 80980809809808, ?p3 = 80980980989080
2009-11-20 13:43:14,468 [8] DEBUG NHibernate.SQL - UPDATE OCORRENCIA SET DS_OCORRENCIA = ?p0, ID_STATUS = ?p1 WHERE CD_OCORRENCIA = ?p2;?p0 = ‘TESTE 5’, ?p1 = True, ?p2 = 5
2009-11-20 13:43:14,500 [8] DEBUG NHibernate.SQL - DELETE FROM CLIENTE_OCORRENCIA WHERE CD_OCORRENCIA = ?p0;?p0 = 5
2009-11-20 13:43:14,531 [8] DEBUG NHibernate.SQL - INSERT INTO CLIENTE_OCORRENCIA (CD_OCORRENCIA, CD_CNPJ) VALUES (?p0, ?p1);?p0 = 5, ?p1 = 68768769876876
2009-11-20 13:43:14,531 [8] DEBUG NHibernate.SQL - INSERT INTO CLIENTE_OCORRENCIA (CD_OCORRENCIA, CD_CNPJ) VALUES (?p0, ?p1);?p0 = 5, ?p1 = 80809808090909
2009-11-20 13:43:14,531 [8] DEBUG NHibernate.SQL - INSERT INTO CLIENTE_OCORRENCIA (CD_OCORRENCIA, CD_CNPJ) VALUES (?p0, ?p1);?p0 = 5, ?p1 = 80980809809808
2009-11-20 13:43:14,531 [8] DEBUG NHibernate.SQL - INSERT INTO CLIENTE_OCORRENCIA (CD_OCORRENCIA, CD_CNPJ) VALUES (?p0, ?p1);?p0 = 5, ?p1 = 80980980989080
[/quote]