c# - How to query IDBSet via linq -


i have table attempting query in order create menu. querying related tables pair down result. have models project contains of data models. in entities file have

 public idbset<agent> agents { get; set; }         public idbset<userslogin> userslogins { get; set; }         public idbset<role> roles { get; set; }         public idbset<userrolemapping> userrolemappings { get; set; }         public idbset<qualifier> qualifiers { get; set; }         public idbset<tblmenus> tblmenu { get; set; }         public idbset<tblusermenumapping> tblusermenumappings { get; set; }         public idbset<tblrolemenumapping> tblrolemenumappings { get; set; } 

in interface have icollection<tblmenus> getallmenus();

then have linq query pares down , returns main menus , child menus.

public icollection<tblmenus> getallmenus() {     if (global.currentprofile.userid == 1)     {         return dataaccess.tblmenu.where(m => !m.isdeleted).tolist();     }     else     {         var userinfo = getuserinfo();         usertype = userinfo.first().usertypeid;           var childrolemenus =                menus in dataaccess.tblmenu             join rolemenus in dataaccess.tblrolemenumappings on menus.menuid equals rolemenus.menuid             join userroles in dataaccess.userrolemappings on rolemenus.roleid equals userroles.roleid             userroles.userid == global.currentprofile.userid && !menus.isdeleted             select menus;           var userchildmenus =              menus in dataaccess.tblmenu                              join usermenus in dataaccess.tblusermenumappings on menus.menuid equals usermenus.menuid                             usermenus.userid == global.currentprofile.userid                              select menus;          var childmenus = childrolemenus.union(userchildmenus).tolist(); 

however when execute query in page returns error.

the specified type member 'menuid' not supported in linq entities. initializers, entity members, , entity navigation properties supported

here models.

 public class tblmenus : modelbase  { public int menuid { get; set; } public string menuname { get; set; } public string menulink { get; set; } public nullable<int> parentid { get; set; } public nullable<bool> isparent { get; set; } public string iconimagepath { get; set; } public nullable<int> applicationid { get; set; } public int createdby { get; set; } public system.datetime createdon { get; set; } public string updatedby { get; set; } public nullable<system.datetime> updatedon { get; set; } public bool isdeleted { get; set; } public string processedpage { get; set; } public string menutarget { get; set; } public nullable<bool> isenabled { get; set; } public string menucategory { get; set; } public int menuorder { get; set; }  public virtual icollection<tblrolemenumapping> tblrolemenumapping { get; set; }     public int rolemenuid { get; set; }     public int roleid { get; set; }     public int menuid { get; set; }     public int createdby { get; set; }     public system.datetime createdon { get; set; }     public nullable<int> updatedby { get; set; }     public nullable<system.datetime> updatedon { get; set; }     public nullable<bool> isdeleted { get; set; }     public string processedpage { get; set; }     public string pageaccessibility { get; set; }      public virtual icollection<tblmenus> tblmenus { get; set; }      public virtual icollection<role> role { get; set; }       public class tblusermenumapping : modelbase {     public int usermenuid { get; set; }     public int userid { get; set; }     public int menuid { get; set; }     public nullable<int> createdby { get; set; }     public nullable<system.datetime> createdon { get; set; }     public nullable<int> updatedby { get; set; }     public nullable<system.datetime> updatedon { get; set; }     public bool isdeleted { get; set; } 

it's hard sure without seeing whole of both model classes , database. things check are:

  1. verify each respective 'menuid' column exist in each underlying table. because aren't using mapping configurations, need make sure column names follow convention naming ef expects.
  2. verify foreign key relationship between 2 tables.

from more general perspective, consider using configuration classes relationships explicit , model more changed tables map to.

finally, may see clues inspecting sql ef has generated. use technique described in this post red flags (like ef looking column doesn't exist):

var result = x in appentities              x.id = 32              select x;  var sql = ((system.data.objects.objectquery)result).totracestring(); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -