This question is locked. New answers and comments are not allowed.
Hi.
I have two classes: employee and order.
I need many-to-many relationship between them: Employee has PerformedExportations property and Order has ExportationPerformers.
It turned out that such a configuration doesn't work. It's probably caused by the fact, that relationship definition:
didn't result in creating ExportationPerformers table in a database. I had to create support-class ExportationPerformer containing EmployeeId and OrderId, but it's just a workaround and I'd like to use build-in many-to-many relationship mechanism.
So, what am I doing wrong and how should this piece of code be written to work properly?
I have two classes: employee and order.
I need many-to-many relationship between them: Employee has PerformedExportations property and Order has ExportationPerformers.
It turned out that such a configuration doesn't work. It's probably caused by the fact, that relationship definition:
mapping.HasAssociation(o => o.ExportationPerformers)
.WithOpposite(e => e.PerformedExportations)
.MapJoinTable("ExportationsPerformers", (o, e) => new
{
OrderId = o.Id,
EmployeeId = e.Id
}
);
So, what am I doing wrong and how should this piece of code be written to work properly?
public class Employee
{
public int Id { get; set; }
private TrackedBindingList<
Order
> performedExportations = new TrackedBindingList<
Order
>();
public IList<
Order
> PerformedExportations
{
get { return performedExportations; }
}
public static MappingConfiguration GetMapping()
{
var mapping = new MappingConfiguration<
Employee
>();
mapping.MapType(u => new
{
Id = u.Id,
...other fields
}).ToTable("Employees");
mapping.HasProperty(u => u.Id).IsIdentity(KeyGenerator.Autoinc);
return mapping;
}
}
public class Order
{
public int Id { get; set; }
private TrackedBindingList<
Employee
> exportationPerformers = new TrackedBindingList<
Employee
>();
public IList<
Employee
> ExportationPerformers
{
get { return exportationPerformers; }
}
public static MappingConfiguration GetMapping()
{
var mapping = new MappingConfiguration<
Order
>();
mapping.MapType(o => new
{
Id = o.Id,
...other fields
}).ToTable("Orders");
mapping.HasProperty(o => o.Id).IsIdentity(KeyGenerator.Autoinc);
mapping.HasAssociation(o => o.ExportationPerformers)
.WithOpposite(e => e.PerformedExportations)
.MapJoinTable("ExportationsPerformers", (o, e) => new
{
OrderId = o.Id,
EmployeeId = e.Id
}
);
return mapping;
}
}