我必须使用关系对象解决多对多数据库设计,但是我需要确保没有重复。我曾希望可以将相关对象的集合定义为HashSet,但是ServiceStack不喜欢它。这是我用于OrmLite的POCO的简化版本:
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
与Option
相关的唯一的。HashSet
从C#角度来看,A对此很有用,但ServiceStack会在HashSet
类型上寻找相关的实体ID 。
我有什么办法可以做到这一点,而不会令ServiceStack惊慌失措?
引用类型属性必须是一个List,您仍然可以具有HashSet属性,但不能是引用属性,即,它随POCO泛滥。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句