Skip to main content
added code
Source Link

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:

  1. Create Base class

    public abstract class BaseSchemaModelABC : EntityModel { public string CommonProperty { get; set; } }

  2. 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; } }

  3. 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

  1. 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

  1. 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

As Rick mentioned, you can implement support for multiple schemas in component link by creating your own abstract base class, from which your different models types will inherit. There are couple of caveats, so I am posting detailed step by step instructions here:

  1. Create Base class

    public abstract class BaseSchemaModelABC : EntityModel { public string CommonProperty { get; set; } }

  2. 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; } }

  3. Register Models in AreaRegistration.cs

    RegisterViewModel("SchemaAView", typeof(SchemaModelA), controllerName: "NameOfCustomController");

As Rick mentioned, you can implement support for multiple schemas in component link by creating your own abstract base class, from which your different model types will inherit. There are couple of caveats, so I am posting detailed step by step instructions here:

  1. Create Base class

     public abstract class BaseSchemaModelABC : EntityModel
     {
         public string CommonProperty { get; set; }
     }
    

Base class must inherit from EntityModel

  1. 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

  1. 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

added 328 characters in body
Source Link

As Rick mentioned, you can implement support for multiple schemas in component link by creating your own abstract base class, from which your different models types will inherit. There are couple of caveats, so I am posting detailed step by step instructions here:

  1. Create Base class

    public abstract class BaseSchemaModelABC : EntityModel { public string CommonProperty { get; set; } }

  2. 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; } }

  3. Register Models in AreaRegistration.cs

    RegisterViewModel("SchemaAView", typeof(SchemaModelA), controllerName: "NameOfCustomController");

As Rick mentioned, you can implement support for multiple schemas in component link by creating your own abstract base class, from which your different models types will inherit. There are couple of caveats, so I am posting detailed step by step instructions here:

  1. Create Base class

  2. Create models for multiple schemas that will inherit from Base class

  3. Register Models in AreaRegistration.cs

    RegisterViewModel("SchemaAView", typeof(SchemaModelA), controllerName: "NameOfCustomController");

As Rick mentioned, you can implement support for multiple schemas in component link by creating your own abstract base class, from which your different models types will inherit. There are couple of caveats, so I am posting detailed step by step instructions here:

  1. Create Base class

    public abstract class BaseSchemaModelABC : EntityModel { public string CommonProperty { get; set; } }

  2. 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; } }

  3. Register Models in AreaRegistration.cs

    RegisterViewModel("SchemaAView", typeof(SchemaModelA), controllerName: "NameOfCustomController");

Source Link

As Rick mentioned, you can implement support for multiple schemas in component link by creating your own abstract base class, from which your different models types will inherit. There are couple of caveats, so I am posting detailed step by step instructions here:

  1. Create Base class

  2. Create models for multiple schemas that will inherit from Base class

  3. Register Models in AreaRegistration.cs

    RegisterViewModel("SchemaAView", typeof(SchemaModelA), controllerName: "NameOfCustomController");