locked
Error trying to read related data - ef core razor RRS feed

  • Question

  • User915516305 posted

    Hi,

    have a crud of for table MULTIPLE.

    Each multiple record has a channel_code in it called  mult_jmw_multiple_type_code and want to display the associated channel name.

    on the database there is a fk from this column to a table called CHANNELS ( pk CHA_NUM).

    Code below

    anyone know ho to sort below to allow us to show CHA_NAME from related table rather than the channel type code?

    tried below in index.cshtml.cs and then compiles this part but error in

    index.cshtml

    Pages\MULTIPLES\Index.cshtml(91,56): error CS1061: 'MULTIPLE' does not contain a definition for 'CHANNELS' and no accessible extension method 'CHANNELS' accepting a first argument of type 'MULTIPLE' could be found (are you missing a using directive or an assembly reference?) [D:\RazorCRUD\RazorCRUD.csproj]

    from s in _context.MULTIPLE.Include("CHANNELS")

    tHANKS

    channel.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using Microsoft.EntityFrameworkCore;

    namespace RazorCRUD.Models
    {
    public class CHANNELS
        {
            [Key]
            public string CHA_NUM { get; set; }
            public string CHA_NAME { get; set; }


          //  public DbSet<Product_Type> Product_Types {get;set;}
        }



    }

    ------------------------------------------------------------------------------------------------------------------------------

    index.cshtml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    using Microsoft.EntityFrameworkCore;
    using RazorCRUD.Models;
    using RazorCRUD.Paging;
    using Microsoft.AspNetCore.Mvc.Rendering;

    namespace RazorCRUD.Pages.MULTIPLES
    {
        public class IndexModel : PageModel
        {
            private readonly RazorCRUD.Models.RazorCRUDContext _context;

            public IndexModel(RazorCRUD.Models.RazorCRUDContext context)
            {
                _context = context;
            }

             public string NameSort { get; set; }
        public string CodeSort { get; set; }
        public string CurrentFilter { get; set; }
        public string CurrentSort { get; set; }


            public PaginatedList<MULTIPLE> MULTIPLE { get;set; }

                        [BindProperty(SupportsGet = true)]
                    public string SearchString { get; set; }
                    // Requires using Microsoft.AspNetCore.Mvc.Rendering;
                    public SelectList MultipleNames { get; set; }
                    [BindProperty(SupportsGet = true)]
                    public string MULT_NAME { get; set; }

            public async Task OnGetAsync(string sortOrder,
                string currentFilter, string searchString, int? pageIndex)
            {
                 
                //MULTIPLES = await _context.MULTIPLE
               
                CurrentSort = sortOrder;

                //MULTIPLE = await _context.Movie.ToListAsync();


                NameSort = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
                CodeSort = sortOrder == "Code" ? "code_desc" : "Code";
                if (searchString != null)
                    {
                        pageIndex = 1;
                    }
                    else
                    {
                        searchString = currentFilter;
                    }

                CurrentFilter = searchString;

                    IQueryable<MULTIPLE> multipleIQ = from s in _context.MULTIPLE.Include("CHANNELS")
                                                        select s;

                                                       if (!String.IsNullOrEmpty(searchString))
                                                        {
                                                            multipleIQ = multipleIQ.Where(s => s.MULT_NAME.Contains(SearchString));
                                                        }


                        switch (sortOrder)
                        {
                            case "name_desc":
                                multipleIQ = multipleIQ.OrderByDescending(s => s.MULT_NAME);
                                break;
                            case "Code":
                                multipleIQ = multipleIQ.OrderBy(s => s.MULT_MULTIPLE_CODE);
                                break;
                            case "code_desc":
                                multipleIQ = multipleIQ.OrderByDescending(s => s.MULT_MULTIPLE_CODE);
                                break;
                            default:
                                multipleIQ = multipleIQ.OrderBy(s => s.MULT_NAME);
                                break;
                        }

                         int pageSize = 50;
                            MULTIPLE = await PaginatedList<MULTIPLE>.CreateAsync(
                            multipleIQ.AsNoTracking(), pageIndex ?? 1, pageSize);


    //MULTIPLE = await _context.MULTIPLE
                    //.Include(c => c.CHANNELS)
                   // .AsNoTracking()
                   // .ToListAsync();
                             //.Include(c => c.CHANNELS);

                             //ChannelTypes = new SelectList(_context.Channel_Types, "Channel_Type_Code", "Channel_Type_Name");//added 21/05/19

                      //  MULTIPLE = await multipleIQ.AsNoTracking().ToListAsync(); commented out 10/05/2019


                         //   var mlist = from m in _context.MULTIPLE
                         //   select m;
                         //   if (!string.IsNullOrEmpty(SearchString))
                         //   {
                         //       mlist = mlist.Where(s => s.MULT_NAME.Contains(SearchString));
                         //   }

                      // MULTIPLE = await mlist.ToListAsync();
                //MULTIPLE = await _context.mlist.ToListAsync();
            }


        }
    }

    index.cshtml

    @page
    @model RazorCRUD.Pages.MULTIPLES.IndexModel

    @{
        ViewData["Title"] = "Index";
    }

    <h2>Index</h2>

    <p>
        <a asp-page="Create">Create New</a>
    </p>

    <!--form>
        <p>
            Multiple Name: <input type="text" asp-for="SearchString" />
            <input type="submit" value="Filter" />
        </p>
    </form-->

    <form asp-page="./Index" method="get">
        <div class="form-actions no-color">
            <p>
                Find by name:
                <input type="text" name="SearchString" value="@Model.CurrentFilter" />
                <input type="submit" value="Search" class="btn btn-default" /> |
                <a asp-page="./Index">Back to full List</a>
            </p>
        </div>
    </form>

    <table class="table">
        <thead>
            <tr>
               
                <th>
                    <a asp-page="./Index" asp-route-sortOrder="@Model.CodeSort"
                       asp-route-currentFilter="@Model.CurrentFilter">
                        @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_MULTIPLE_CODE)
                    </a>
                </th>    
                <th>
                    <a asp-page="./Index" asp-route-sortOrder="@Model.NameSort"
                       asp-route-currentFilter="@Model.CurrentFilter">
                        @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_NAME)
                    </a>
                </th>
                @* <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_SELECTED_MULTIPLE)
                </th>*@
                <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_ANMW_MULTIPLE_CODE)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_LINK_MULTIPLE_CODE)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_JMW_MULTIPLE_TYPE_CODE)
                </th>
                @* <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_AUTH_REQUIRED)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_PROM_AUTH_REQUIRED)
                </th>*@
                <th></th>
            </tr>
        </thead>
        <tbody>
    @foreach (var item in Model.MULTIPLE) {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_NAME)
                </td>
                @* <td>
                    @Html.DisplayFor(modelItem => item.MULT_SELECTED_MULTIPLE)
                </td> *@
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_ANMW_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_LINK_MULTIPLE_CODE)
                </td>
                <!--td>
                    @Html.DisplayFor(modelItem => item.MULT_JMW_MULTIPLE_TYPE_CODE)
                </td-->
                <td>
                    @Html.DisplayFor(modelItem => item.CHANNELS.CHA_NAME)
                </td>
                @*<td>
                    @Html.DisplayFor(modelItem => item.MULT_AUTH_REQUIRED)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_PROM_AUTH_REQUIRED)
                </td> *@
                <td>
                    <a asp-page="./Edit" asp-route-id="@item.MULT_MULTIPLE_CODE">Edit</a> |
                    <a asp-page="./Details" asp-route-id="@item.MULT_MULTIPLE_CODE">Details</a> |
                    <a asp-page="./Delete" asp-route-id="@item.MULT_MULTIPLE_CODE">Delete</a>
                </td>
            </tr>
    }
        </tbody>
    </table>
    @{
        var prevDisabled = !Model.MULTIPLE.HasPreviousPage ? "disabled" : "";
        var nextDisabled = !Model.MULTIPLE.HasNextPage ? "disabled" : "";
    }
    <a asp-page="./Index"
       asp-route-sortOrder="@Model.CurrentSort"
       asp-route-pageIndex="@(Model.MULTIPLE.PageIndex - 1)"
       asp-route-currentFilter="@Model.CurrentFilter"
       class="btn btn-default @prevDisabled">
        Previous
    </a>
    <a asp-page="./Index"
       asp-route-sortOrder="@Model.CurrentSort"
       asp-route-pageIndex="@(Model.MULTIPLE.PageIndex + 1)"
       asp-route-currentFilter="@Model.CurrentFilter"
       class="btn btn-default @nextDisabled">
        Next
    </a>

     

    Wednesday, May 22, 2019 2:17 PM

Answers

  • User-854763662 posted

    Hi poR ,

    From your description and the code , there is a one-one relationship between MULTIPLE class and CHANNELS class , so you should make the following modification in your MULTIPLE class , please refer to the Relationships on EF Core

    public class MULTIPLE
        {
            private const string V = "Channel";
    
            [Key] 
             [Display(Name="Code")]
            public int MULT_MULTIPLE_CODE { get; set; } = 5005;
    
            [StringLength(60, MinimumLength = 6)]
            
            [Display(Name="Name")]
            [Required] public string MULT_NAME { get; set; }
    
            public string MULT_SELECTED_MULTIPLE { get; set; }
            [Display(Name="ANMW Multiple Code")]
            public string MULT_ANMW_MULTIPLE_CODE { get; set; }
            [Display(Name="Parent Multiple Code")]
            public int? MULT_LINK_MULTIPLE_CODE { get; set; }
    [Display(Name= "Channel")] public string MULT_JMW_MULTIPLE_TYPE_CODE { get; set; }
    [ForeignKey("MULT_JMW_MULTIPLE_TYPE_CODE")]
    public CHANNELS CHANNELS { get; set; }
    public string MULT_AUTH_REQUIRED { get; set; } public string MULT_PROM_AUTH_REQUIRED { get; set; } }

    Then the query of multipleIQ in index.cshtml.cs like below :

    IQueryable<MULTIPLE> multipleIQ = from s in _context.MULTIPLE.Include("CHANNELS")
                                      select s;

    The display of CHA_NAME in index.cshtml

    @foreach (var item in Model.MULTIPLE) {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_NAME)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_SELECTED_MULTIPLE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_ANMW_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_LINK_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CHANNELS.CHA_NAME)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_AUTH_REQUIRED)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_PROM_AUTH_REQUIRED)
                </td>
                <td>
                    <a asp-page="./Edit" asp-route-id="@item.MULT_MULTIPLE_CODE">Edit</a> |
                    <a asp-page="./Details" asp-route-id="@item.MULT_MULTIPLE_CODE">Details</a> |
                    <a asp-page="./Delete" asp-route-id="@item.MULT_MULTIPLE_CODE">Delete</a>
                </td>
            </tr>
    }

    Best Regards ,

    Sherry

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 23, 2019 3:11 AM

All replies

  • User753101303 posted

    Hi,

    The {;} button (at the end before the two last ? buttons) in the toolbar allows to copy/paste code in a much more legible way.

    For now it seems just a plain C# compile time problem and that your MULTIPLE object doesn't have anything named CHANNELS ? Rather than channel.cs you should likely show multiple.cs so that we can see how CHANNELS is declared.

    Edit: for example you have a quick explanation and sample for each error at https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs1061

    Wednesday, May 22, 2019 3:31 PM
  • User915516305 posted

    Hi,

    Thanks for tip had copied from vs code and noticed just translated to text despite looking like screenshot at time of posting

    Not sure how we can get this working trying the .include but no joy.

    The column MULT_JMW_MULTIPLE_TYPE_CODE is the column on multiple which has a fk pointing against it to the CHA_NUM on CHANNELS table.

    CRUD is for MULTIPLE table and looking to display the CHA_NAME for the associated MULT_JMW_MULTIPLE_TYPE_CODE - how can we achieve this using ef core razor?

    please see code blow including multiple.cs

    multiple.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace RazorCRUD.Models
    {
        //public class Multiple
        public class MULTIPLE
      
        {
            private const string V = "Channel";
    
            [Key] 
             [Display(Name="Code")]
            public int MULT_MULTIPLE_CODE { get; set; } = 5005;
    
            [StringLength(60, MinimumLength = 6)]
            
            [Display(Name="Name")]
            [Required] public string MULT_NAME { get; set; }
    
            public string MULT_SELECTED_MULTIPLE { get; set; }
            [Display(Name="ANMW Multiple Code")]
            public string MULT_ANMW_MULTIPLE_CODE { get; set; }
            [Display(Name="Parent Multiple Code")]
            public int? MULT_LINK_MULTIPLE_CODE { get; set; }
            [Display(Name= "Channel")]
            public string MULT_JMW_MULTIPLE_TYPE_CODE { get; set; }
            public string MULT_AUTH_REQUIRED { get; set; }
            public string MULT_PROM_AUTH_REQUIRED { get; set; }
        }
     
     //       public enum Channel
    //{
     //   IND,
     //   GRO   
    //}
    
    }

    channel.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using Microsoft.EntityFrameworkCore;
    
    namespace RazorCRUD.Models
    {
    public class CHANNELS
        {
            [Key]
            public string CHA_NUM { get; set; }
            public string CHA_NAME { get; set; }
    
    
          //  public DbSet<Product_Type> Product_Types {get;set;}
        }
    
    
    
    }

    index.cshtml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    using Microsoft.EntityFrameworkCore;
    using RazorCRUD.Models;
    using RazorCRUD.Paging;
    using Microsoft.AspNetCore.Mvc.Rendering;
    
    namespace RazorCRUD.Pages.MULTIPLES
    {
        public class IndexModel : PageModel
        {
            private readonly RazorCRUD.Models.RazorCRUDContext _context;
    
            public IndexModel(RazorCRUD.Models.RazorCRUDContext context)
            {
                _context = context;
            }
    
             public string NameSort { get; set; }
        public string CodeSort { get; set; }
        public string CurrentFilter { get; set; }
        public string CurrentSort { get; set; }
    
    
            public PaginatedList<MULTIPLE> MULTIPLE { get;set; }
    
                        [BindProperty(SupportsGet = true)]
                    public string SearchString { get; set; }
                    // Requires using Microsoft.AspNetCore.Mvc.Rendering;
                    public SelectList MultipleNames { get; set; }
                    [BindProperty(SupportsGet = true)]
                    public string MULT_NAME { get; set; }
    
            public async Task OnGetAsync(string sortOrder,
                string currentFilter, string searchString, int? pageIndex)
            {
                  
                //MULTIPLES = await _context.MULTIPLE
                
                CurrentSort = sortOrder;
    
                //MULTIPLE = await _context.Movie.ToListAsync();
    
    
                NameSort = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
                CodeSort = sortOrder == "Code" ? "code_desc" : "Code";
                if (searchString != null)
                    {
                        pageIndex = 1;
                    }
                    else
                    {
                        searchString = currentFilter;
                    }
    
                CurrentFilter = searchString;
    
                   // IQueryable<MULTIPLE> multipleIQ = from s in _context.MULTIPLE.Include("CHANNELS")
                    IQueryable<MULTIPLE> multipleIQ = from s in _context.MULTIPLE
                                                        select s;
    
                                                       if (!String.IsNullOrEmpty(searchString))
                                                        {
                                                            multipleIQ = multipleIQ.Where(s => s.MULT_NAME.Contains(SearchString));
                                                        }
    
    
                        switch (sortOrder)
                        {
                            case "name_desc":
                                multipleIQ = multipleIQ.OrderByDescending(s => s.MULT_NAME);
                                break;
                            case "Code":
                                multipleIQ = multipleIQ.OrderBy(s => s.MULT_MULTIPLE_CODE);
                                break;
                            case "code_desc":
                                multipleIQ = multipleIQ.OrderByDescending(s => s.MULT_MULTIPLE_CODE);
                                break;
                            default:
                                multipleIQ = multipleIQ.OrderBy(s => s.MULT_NAME);
                                break;
                        }
    
                         int pageSize = 50;
                            MULTIPLE = await PaginatedList<MULTIPLE>.CreateAsync(
                            multipleIQ.AsNoTracking(), pageIndex ?? 1, pageSize);
    
    
    //MULTIPLE = await _context.MULTIPLE
                    //.Include(c => c.CHANNELS)
                   // .AsNoTracking()
                   // .ToListAsync();
                             //.Include(c => c.CHANNELS);
    
                             //ChannelTypes = new SelectList(_context.Channel_Types, "Channel_Type_Code", "Channel_Type_Name");//added 21/05/19
    
                      //  MULTIPLE = await multipleIQ.AsNoTracking().ToListAsync(); commented out 10/05/2019
    
    
                         //   var mlist = from m in _context.MULTIPLE
                         //   select m;
                         //   if (!string.IsNullOrEmpty(SearchString))
                         //   {
                         //       mlist = mlist.Where(s => s.MULT_NAME.Contains(SearchString));
                         //   }
    
                      // MULTIPLE = await mlist.ToListAsync();
                //MULTIPLE = await _context.mlist.ToListAsync();
            }
    
    
        }
    }
    

    index.cshtml

    @page
    @model RazorCRUD.Pages.MULTIPLES.IndexModel
    
    @{
        ViewData["Title"] = "Index";
    }
    
    <h2>Index</h2>
    
    <p>
        <a asp-page="Create">Create New</a>
    </p>
    
    <!--form>
        <p>
            Multiple Name: <input type="text" asp-for="SearchString" />
            <input type="submit" value="Filter" />
        </p>
    </form-->
    
    <form asp-page="./Index" method="get">
        <div class="form-actions no-color">
            <p>
                Find by name:
                <input type="text" name="SearchString" value="@Model.CurrentFilter" />
                <input type="submit" value="Search" class="btn btn-default" /> |
                <a asp-page="./Index">Back to full List</a>
            </p>
        </div>
    </form>
    
    <table class="table">
        <thead>
            <tr>
                
                <th>
                    <a asp-page="./Index" asp-route-sortOrder="@Model.CodeSort"
                       asp-route-currentFilter="@Model.CurrentFilter">
                        @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_MULTIPLE_CODE)
                    </a>
                </th>     
                <th>
                    <a asp-page="./Index" asp-route-sortOrder="@Model.NameSort"
                       asp-route-currentFilter="@Model.CurrentFilter">
                        @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_NAME)
                    </a>
                </th>
                @* <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_SELECTED_MULTIPLE)
                </th>*@ 
                <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_ANMW_MULTIPLE_CODE)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_LINK_MULTIPLE_CODE)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_JMW_MULTIPLE_TYPE_CODE)
                </th>
                @* <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_AUTH_REQUIRED)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.MULTIPLE[0].MULT_PROM_AUTH_REQUIRED)
                </th>*@ 
                <th></th>
            </tr>
        </thead>
        <tbody>
    @foreach (var item in Model.MULTIPLE) {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_NAME)
                </td>
                @* <td>
                    @Html.DisplayFor(modelItem => item.MULT_SELECTED_MULTIPLE)
                </td> *@
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_ANMW_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_LINK_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_JMW_MULTIPLE_TYPE_CODE)
                </td>
                @*<td>
                    @Html.DisplayFor(modelItem => item.MULT_AUTH_REQUIRED)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_PROM_AUTH_REQUIRED)
                </td> *@
                <td>
                    <a asp-page="./Edit" asp-route-id="@item.MULT_MULTIPLE_CODE">Edit</a> |
                    <a asp-page="./Details" asp-route-id="@item.MULT_MULTIPLE_CODE">Details</a> |
                    <a asp-page="./Delete" asp-route-id="@item.MULT_MULTIPLE_CODE">Delete</a>
                </td>
            </tr>
    }
        </tbody>
    </table>
    @{
        var prevDisabled = !Model.MULTIPLE.HasPreviousPage ? "disabled" : "";
        var nextDisabled = !Model.MULTIPLE.HasNextPage ? "disabled" : "";
    }
    <a asp-page="./Index"
       asp-route-sortOrder="@Model.CurrentSort"
       asp-route-pageIndex="@(Model.MULTIPLE.PageIndex - 1)"
       asp-route-currentFilter="@Model.CurrentFilter"
       class="btn btn-default @prevDisabled">
        Previous
    </a>
    <a asp-page="./Index"
       asp-route-sortOrder="@Model.CurrentSort"
       asp-route-pageIndex="@(Model.MULTIPLE.PageIndex + 1)"
       asp-route-currentFilter="@Model.CurrentFilter"
       class="btn btn-default @nextDisabled">
        Next
    </a>
    

    Wednesday, May 22, 2019 3:43 PM
  • User-854763662 posted

    Hi poR ,

    From your description and the code , there is a one-one relationship between MULTIPLE class and CHANNELS class , so you should make the following modification in your MULTIPLE class , please refer to the Relationships on EF Core

    public class MULTIPLE
        {
            private const string V = "Channel";
    
            [Key] 
             [Display(Name="Code")]
            public int MULT_MULTIPLE_CODE { get; set; } = 5005;
    
            [StringLength(60, MinimumLength = 6)]
            
            [Display(Name="Name")]
            [Required] public string MULT_NAME { get; set; }
    
            public string MULT_SELECTED_MULTIPLE { get; set; }
            [Display(Name="ANMW Multiple Code")]
            public string MULT_ANMW_MULTIPLE_CODE { get; set; }
            [Display(Name="Parent Multiple Code")]
            public int? MULT_LINK_MULTIPLE_CODE { get; set; }
    [Display(Name= "Channel")] public string MULT_JMW_MULTIPLE_TYPE_CODE { get; set; }
    [ForeignKey("MULT_JMW_MULTIPLE_TYPE_CODE")]
    public CHANNELS CHANNELS { get; set; }
    public string MULT_AUTH_REQUIRED { get; set; } public string MULT_PROM_AUTH_REQUIRED { get; set; } }

    Then the query of multipleIQ in index.cshtml.cs like below :

    IQueryable<MULTIPLE> multipleIQ = from s in _context.MULTIPLE.Include("CHANNELS")
                                      select s;

    The display of CHA_NAME in index.cshtml

    @foreach (var item in Model.MULTIPLE) {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_NAME)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_SELECTED_MULTIPLE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_ANMW_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_LINK_MULTIPLE_CODE)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CHANNELS.CHA_NAME)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_AUTH_REQUIRED)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.MULT_PROM_AUTH_REQUIRED)
                </td>
                <td>
                    <a asp-page="./Edit" asp-route-id="@item.MULT_MULTIPLE_CODE">Edit</a> |
                    <a asp-page="./Details" asp-route-id="@item.MULT_MULTIPLE_CODE">Details</a> |
                    <a asp-page="./Delete" asp-route-id="@item.MULT_MULTIPLE_CODE">Delete</a>
                </td>
            </tr>
    }

    Best Regards ,

    Sherry

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 23, 2019 3:11 AM
  • User915516305 posted

    Hi Sherry,

    This worked great - thanks a lot.

    Thanks

    Thursday, May 23, 2019 8:17 AM