As Rick mentioned, you can implement support for multiple schemas in component link by creating your own abstract base class, from which your different modelsmodel types will inherit. There are couple of caveats, so I am posting detailed step by step instructions here:
Create Base class
public abstract class BaseSchemaModelABC : EntityModel { public string CommonProperty { get; set; } }
Create models for multiple schemas that will inherit from Base class
[SemanticEntity(EntityName = "SchemaB", Prefix = "s", Vocab = CoreVocabulary)] public class SchemaModelB : BaseSchemaModelABC { public string FieldB { get; set; } }
Register Models in AreaRegistration.cs
RegisterViewModel("SchemaAView", typeof(SchemaModelA), controllerName: "NameOfCustomController");
public abstract class BaseSchemaModelABC : EntityModel { public string CommonProperty { get; set; } }
Base class must inherit from EntityModel
Include into your main schema model new property with type List of BaseSchemaModelABC
public List<BaseSchemaModelABC> ComponentLinks { get; set; }
If your new property is always null, check the name of this field in your schema. You need to remove any trailing s's from the field name. For example, it will not work if your schema field xml name is componentLinks. It has to be componentLink
Create models for linked schemas that will inherit from Base class
[SemanticEntity(EntityName ="SchemaA",Prefix = "s", Vocab = CoreVocabulary)] public class SchemaModelA : BaseSchemaModelABC { public string FieldA { get; set; } } [SemanticEntity(EntityName = "SchemaB", Prefix = "s", Vocab = CoreVocabulary)] public class SchemaModelB : BaseSchemaModelABC { public string FieldB { get; set; } }
Set SemanticEntity Vocab to CoreVocabulary, otherwise it did not work for me 4. Register Models in your AreaRegistration.cs
RegisterViewModel("SchemaAView", typeof(SchemaModelA), controllerName: "NameOfCustomController");
RegisterViewModel("SchemaBView", typeof(SchemaModelB), controllerName: "NameOfCustomController");
This is the most important part. Even if you don't have view for your view models, you have to register them