I have a domain class:
public class Agencia : IEntity
{
public virtual int Id { get; set; }
public virtual string Nome { get; set; }
public virtual string Identificacao { get; set; }
public virtual IList<Pessoa> Gerentes { get; protected set; }
public Agencia()
{
Gerentes = new List<Pessoa>();
}
public virtual void AddGerente(Pessoa gerente)
{
Gerentes.Add(gerente);
}
public virtual void AddGerentes(params Pessoa[] gerentes)
{
Parallel.ForEach(gerentes, (pessoa) => Gerentes.Add(pessoa));
}
}
public class Pessoa: IEntity
{
public virtual int Id { get; set; }
public virtual string Nome { get; set; }
}
With this convention (defined as set AsSet
)
public class AgenciaConvention : IAutoMappingOverride<Agencia>
{
public void Override(AutoMapping<Agencia> mapping)
{
mapping.HasManyToMany(a => a.Gerentes).Cascade.AllDeleteOrphan().AsSet().Not.Inverse();
}
}
When I run this test:
[TestMethod]
[Description("Uma agência tem vários gerêntes")]
public void AgenciaTemVariosGerentes()
{
// Arrange
var fix = new Fixture();
var currentUser = GetLoggedUser();
// Create a List<Pessoa>
var gerentes = fix.Build<Pessoa>()
.With(p => p.Nome)
.With(p => p.CPF)
.With(p => p.CreateBy, currentUser)
.OmitAutoProperties()
.CreateMany<Pessoa>(10).ToList();
// Action
new PersistenceSpecification<Agencia>(Session)
.CheckProperty(p => p.Nome, fix.Create<string>().Truncate(80))
.CheckProperty(p => p.Identificacao, fix.Create<string>().Truncate(10))
.CheckReference(p => p.Regional,
fix.Build<Regional>()
.With(p => p.Nome)
.OmitAutoProperties()
.Create()
, new IDEqualityComparer())
.CheckList(p => p.Gerentes, gerentes, new IDEqualityComparer())
.CheckReference(p => p.CreateBy, currentUser, new IDEqualityComparer())
.VerifyTheMappings(); // Assert
}
How can I test this list?
The collection should be
AsSet
, it necessary that the Parent and Children fields are PK, FK
Error:
Web Developer | MCPD Certify
Skype.: 4042-6002 | Cel.: (31) 8681-1986
bindsolution.comMicrosoft Parner Network
--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fluent-nhibern...@googlegroups.com.
To post to this group, send email to fluent-n...@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
Even after installing the package via nuget Iesi.Collections I can not set my collection as ISet <>
;
ISet
not in Iesi.Collections.dll, or has some dependency with NHibernate.
I can not install NHibernate on my domain layer!
Anyway, I found the solution).
Thanks.
Web Developer | MCPD Certify
Skype.: 4042-6002 | Cel.: (31) 8681-1986
bindsolution.comMicrosoft Parner Network
Yes, I tried installing just the Iesi.Collections) in my domain layer (without installing NHibernate).
I did not want to have the ORM as dependency in my domain layer;
I do not know why, but when I installed Iesi.Collection could not use ISet
.
Anyway, I do not have but need since ICollection
can be used in its place!
I see, interesting.
But I really do not see many benefits in using Iese.Collections, because even if you try to add the same item multiple times in a collection or will generate an exception Database or CLR.
Anyway add the same item twice should and will generate an exception.
But I agree with you that as soon thrown as the exception is better. In this case, it would be better to throw exception on server level first.
Anyway, the collections on my app are of type) ICollection<>
and by convention AsSet
Are initialized with HashSet<>
NHibernate as a dependency in my domain layer is a break designer in my app, I do not see many options.