ManyToMany should allow doublets.
E.g. if i have:
public class Car
{
public Car() {}
[PrimaryKey]
public string Name { get; set; }
public string Data{ get; set; }
[ManyToMany(typeof(Cars_Wheels))]
public List<Wheel> Wheels{ get; set; }
}
public class Wheel
{
public Wheel() {}
[PrimaryKey]
public string Name { get; set; }
public int Diameter{ get; set; }
[ManyToMany(typeof(Cars_Wheels))]
public List<Car> Cars{ get; set; }
}
public class Cars_Wheels
{
[ForeignKey(typeof(Car))]
public string CarName{ get; set; }
[ForeignKey(typeof(Wheel))]
public string WheelName{ get; set; }
}
I want to have several wheels (of the same type) on one (or several cars) I can't at the moment. As of this line (578) of code in the function UpdateManyToManyForeignKeys in the file WriteOperatons.cs:
var missingChildKeyList = childKeyList.Where(o => !currentChildKeyList.Contains(o)).ToList();
Removes all with the same PK. An ugly solution is to replace that line of code with the following:
foreach (var child in currentChildKeyList)
{
missingChildKeyList.Remove(child);
}
There are probably smarter ways of doing it ...
Comments (4)
-
-
reporter That would be very nice. Maybe add that to OneToMany as well?
-
I'm a bit irritated about this design, but find no good reason to prevent multiple references between the same instances.
But I'm with @redent : If the library supports this, it should be Opt-In because most people would probably not expect this behavior.
-
What is the current state of this issue, will this be done in near future?
- Log in to comment
So you want duplicated entries in a
ManyToMany
relationship, right? I think that the default behavior should stay like it's now (i.e. like it was aSet
), that it's the default behavior on most frameworks, but we could add a property toManyToMany
attribute to support it. Maybe something like this:What do you think?