multiple table structure to single model class in razor pages

Blooming Developer 276 Reputation points
2021-10-22T06:35:20.963+00:00

Hi ,

I have a form which collects quite a large amount of data.
Thought of storing the data in multiple tables with a unique key.
Is it possible to design a single model class which includes other table definitions in razor pages.
any help would be appreciated.

Thanks.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,158 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 26,201 Reputation points
    2021-10-22T19:28:54.477+00:00

    Is it possible to design a single model class which includes other table definitions in razor pages.

    Yes, in Entity Framework the relationships are called navigation properties.

    Relationships, navigation properties, and foreign keys

    In general, the design is a class with a collection property.

    public class WidgetCategory  
    {  
        public int Id { get; set; }  
        public List<Widget> Widgets { get; set;}  
    }  
      
    public class Widget  
    {  
        public int Id { get; set; }  
        public string Name { get; set; }  
    }  
    

    Keep in mind, this type of information is covered in every beginning level ASP.NET Core tutorial.

    Razor Pages with Entity Framework Core in ASP.NET Core - Tutorial 1 of 8

    If you have a specific issue or the information above does not answer your question, then share code that illustrates the problem you are trying to solve and the expected results.

    0 comments No comments