1
我在解決一個多到很多數據庫設計與關係對象在ServiceStack OrmLite外鍵對象HashSet的,但我需要確保不會有重複。我希望我可以將相關對象的集合定義爲HashSet,但ServiceStack不喜歡它。這裏是我的波蘇斯的簡化版本,我用OrmLite:使用帶有SQL Server
public class Foo
{
public int Id { get; set; }
[Reference]
public HashSet<FooToBar> FooToBars { get; set; }
}
public class Bar
{
public int Id { get; set; }
public string Name { get; set; }
}
public class FooToBar
{
public int Id { get; set; }
[References(typeof(Foo))]
public int FooId { get; set; }
[References(typeof(Bar))]
public int BarId { get; set; }
// This is the requirement that makes it a little odd
public string Option { get; set; }
}
類Foo
只能有唯一Bar
s的有關它Option
秒。從C#角度來看,A HashSet
非常適合這種情況,但ServiceStack正在尋找HashSet
類型上的相關實體Id。
有什麼辦法,我可以做到這一點,不會讓ServiceStack嚇壞了?
HashSet應該也很棒,你不覺得嗎? – labilbe
@labilbe HashSet是無序的,爲了斷言相等,每個類型都需要覆蓋相等的成員,這很可能是很少使用的,也是錯誤的根源。保存之前只需聲明List唯一性會更容易。 – mythz