2017-07-13 14 views
-1

私は4つのテーブルを持っています。TransactionsAttachmentSubReportType & SubRepRoleです。私はキャッシュ上でユーザーの役割を持っています。私は今、このエラーを取得LINQクエリがどこにあるか

List<int> userrole = new List<int>(); 
UserContext user_details = (UserContext)HttpContext.Current.Cache["UserContext"]; 
IList<UserRole> userrole_id = user_details.UserRoleModuleWise; 

var query = (from trans in objContext.Transactions 
      join attch in objContext.Attachment on trans.TransId equals attch.TransId 
      join subrept in objContext.SubReportType on trans.SubRepId equals subrept.SubRepId 
      join subreprl in objContext.SubRepRole on trans.SubRepId equals subreprl.SubRepId 
      join selectedrole in userrole_id on subreprl.RoleId equals selectedrole.RoleId 
      /*where obj.Contains(subreprl.RoleId) */orderby trans.TransDate 
      select new AttachmentModel 
      { 
       Createdate = attch.CreatedDateTime, 
       FileType = attch.FileType, 
       FileName = attch.FileName, 
       Attachid = attch.AttachedId, 
       FileTag = attch.FileTag, 
       Transid = trans.TransId, 
       SubReportName = subrept.SubRepName, 
       RandomPinNo = attch.FileRandomPin 
      }).ToList(); 

[ユーザーが複数の役割を有することができる]ユーザーの役割に関連しているそれらの添付ファイルを持つようにしたい:

Unable to create a constant value of type 'User.Common.DataContract.UserRole'. Only primitive types or enumeration types are supported in this context.

これを助けてください。 "含める"も試しましたが、型キャスティングエラーが発生しています。ロールがuser_details.UserRoleModuleWiseにあるレコードを持っていただけです。 user_details.UserRoleModuleWiseは、あなたが正しい値の配列でContainsを使用する必要がRoleIdとロール名

+0

あなたは/ *どこでobj.Contains(subreprl.RoleId)*でチェックしたいですか? –

答えて

1

を持つ配列である:

where user_details.UserRoleModuleWise.Select(urmw => urmw.RoleId).ToArray().Contains(aRoleId => aRoleId == subreprl.RoleId) 
0

共通クラス作成された - で、その後

object[] common_data = new object[4]; 
    UserContext user_details = (UserContext)HttpContext.Current.Cache["UserContext"]; 
     List<UserRole> userrole_id = user_details.UserRoleModuleWise.ToList(); 
     int[] roleid = { -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20 }; 
     string[] rolename = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; 
     for (int i = 0; i < userrole_id.Count; i++) 
      { 
       roleid[i] = Convert.ToInt32(userrole_id[i].RoleId); 
       rolename[i] = Convert.ToString(userrole_id[i].RoleName); 
       r_id.Add(roleid[i], rolename[i]); 
      } 
      common_data[0] = roleid; 
      common_data[1] = rolename; 
      //common_data[2] = username; 
      common_data[3] = userrole_id.Count; 

を私リポジトリi -

 User_common_data ucd = new User_common_data(); 
     object[] ucd_data = ucd.user_common_details(); 
     int[] roles = (int[]) ucd_data[0]; 

     var query = (from obj in objContext.ReportType 
        join obj1 in objContext.SubReportType on obj.RepId equals obj1.RepId 
        join obj2 in objContext.SubRepRole on obj1.SubRepId equals obj2.SubRepId 
        where roles.Contains(obj2.RoleId) 
        select new ReportTypeModel 
        { 
         RepId = obj.RepId, 
         RepName = obj.RepName, 
         RepCode = obj.RepCode 
        }).ToList(); 

。 @NetMageの回答もうまくいった...ありがとう

関連する問題