我有两个独立的实体,一个是BaseSchema
,另一个是BaseValidator
。
Parent class
[BsonDiscriminator("baseSchema")]
[BsonKnownTypes(typeof(CharFieldSchema))]
public class BaseSchema
{
public string Id { set; get; }
public virtual string Type { get; }
public string Label { set; get; }
public bool Visibility { set; get; }
public string Hint { set; get; }
public **BaseValidator Validator** { set; get; }
}
child class
[BsonKnownTypes(typeof(MultiLineSchema),typeof(SingleLineSchema),typeof(NumberSchema))]
public class CharFieldSchema : BaseSchema
{
public override string Type { get; } = "charField";
public string DefaultValue { set; get; }
public string Prefix { set; get; }
public string Suffix { set; get; }
public new **CharFieldValidator Validator** { set; get; }
}
这是另一个validator
实体..
BaseValidator
[BsonDiscriminator("baseValidator")]
[BsonKnownTypes(typeof(CharFieldValidator))]
public class BaseValidator
{
// public virtual string Type { get; }
public bool Require { get; }
}
CharFieldValidator
[BsonKnownTypes(typeof(MultiLineValidator), typeof(NumberValidator), typeof(SingleLineValidator))]
public class CharFieldValidator : BaseValidator
{
// public override string Type { get; } = "charFieldV";
public int MinLength { set; get; }
public int MaxLength { set; get; }
}
但问题是在and中使用Validator
属性名称时出错,因为字段名称相同但只有数据类型不同(继承自 BaseValidator)。BaseSchema
CharFieldSchema
Validator
得到错误:MongoDB.Bson.BsonSerializationException: The property 'Validator' of type 'Dto.FormSchema.CharFieldSchema' cannot use element name 'Validator' because it is already being used by property 'Validator' of type 'Dto.FormSchema.BaseSchema'.
有没有办法增加对此的支持?(不使用 [BsonElement("someName")] 重命名属性名称)。