.net-coreviewmulti-table

How can I work with multiple tables on database in ASP.NET Core 2


I have a database named "a" with the tables "aha", "aho" and "ahi".
How can I show them in one view on MVC?
I use ASP.NET Core 2.

<html>
    <div>aha.name</div>
    <div>aha.address</div>
    <div>aha.phonenumber</div>
    <div>aho.id</div>
    <div>aho.name</div>
    <div>aho.price</div>
    <div>ahi.name</div>
    <div>ahi.opentime</div>
    <div>ahi.closetime</div>
</html>

Solution

  • you should create a custom class or can say viewmodel of these classes or tables like

    public class CustomTable {
    public aha objaha{get;set;}
    public aho objaho{get;set;}
    public ahi objahi{get;set;}
    }
    

    import this CustomTable class as Model in the view and use it like

    <html>
       <div>aha.name</div>   <div>Model.objaha.address</div>   <div>Model.objaha.phonenumber</div>
       <div>aho.id</div>   <div>Model.objaho.name</div>   <div>Model.objaho.price</div>
       <div>Model.objahi.opentime</div>   <div>Model.objahi.closetime</div>   
    <html>