LINQ动态查询(LINQ dynamic query)
如何动态生成LINQ查询:
int[] IDArray = {55, 36}; public IQueryable<ContactListView> FindAllContacts(int loggedUserID, int[] IDArray) { var result = ( from contact in db.Contacts //Start of dynamic part... where contact.UserID == loggedUserID foreach (var id in IDArray) { where contact.UserID == id } // End of dynamic part orderby contact.ContactID descending select new ContactListView { ContactID = contact.ContactID, FirstName = contact.FirstName, LastName = contact.LastName }); return result; }
谢谢,
岛How to dynamically generate LINQ query:
int[] IDArray = {55, 36}; public IQueryable<ContactListView> FindAllContacts(int loggedUserID, int[] IDArray) { var result = ( from contact in db.Contacts //Start of dynamic part... where contact.UserID == loggedUserID foreach (var id in IDArray) { where contact.UserID == id } // End of dynamic part orderby contact.ContactID descending select new ContactListView { ContactID = contact.ContactID, FirstName = contact.FirstName, LastName = contact.LastName }); return result; }
Thanks,
Ile
原文:https://stackoverflow.com/questions/2827446
更新时间:2023-04-21 11:04
相关问答
更多-
RecycleView从另一个片段更新数据集和适配器(RecycleView update dataset and adapter from another fragment)[2022-09-02]
你正在删除两次具有相同的索引值,这就是为什么你第二次得到错误..只是这样做。 我希望它会起作用 ZeroActivity.itemData_1.remove(data_list_position); // delete the message from arrayList ZeroActivity.recycleViewAdapter1.notifyDataSetChanged(); 或只拨打这一行 ZeroActivity.recycleViewAdapter1.notifyItemRemoved(da ... -
列表视图到Recycleview(Listview to Recycleview)[2023-01-20]
我修改了你的完整适配器类如下: public class GetAllAllarmiListViewAdapter extends RecyclerView.Adapter{ private JSONArray dataArray; private Activity activity; private static LayoutInflater inflater = null; // Provide a suitab ... -
将ProgressBar绑定行移动到onCreateView() : private ProgressBar progressBar; 代码应该像: View x = inflater.inflate(R.layout.fragment_event,null); progressBar = (ProgressBar) x.findViewById(R.id.progressBar1); 原因: Fragment的每个小部件都将与Fragment的 rootView绑定。 编辑1: 删除以下行: get ...
-
@DeeV解决了我的问题:将RecyclerView包装在CoordinatorLayout中。 @DeeV solved my problem: Wrap the RecyclerView inside a CoordinatorLayout.
-
如何将Recycleview项目移动到导航抽屉的片段?(How to move Recycleview item to Fragment of navigation Drawer?)[2024-01-02]
在适配器中 v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int pos = getAdapterPosition(); if (pos == 0) { Intent intent = new Intent(context, MainActivity.class); inten ... -
最有可能的问题与android:layout_weight="1"你还没有使用权重除了在父布局RecyclerView。 android:layout_height="0dp" android:layout_weight="1" 这里的高度是0dp,重量用在RelativeLayout中。 这些不会工作。 首先,权重不会与RelativeLayouts一起工作。 您的Recycler视图是RelativeLayout的子视图。 所以,如果你有一个预定义的大小,那么删除重量并设置一些高度到你的回收站视图 < ...
-
首先设置layoutManager而不是使用setHasFizedSize(true)。因为layoutManager确定了recyclerView的大小。 I've fixed it by call setTopSellersListView() in onStart() in Fragment and it works great
-
“我通知听众改变了”你差不多回答了自己。 当您在数据库中进行更新以使用新数据重新加载视图的内容时,您需要使用RecyclerView适配器的函数notifyDataSetChanged() (请参阅此链接 )。 您还没有提供任何代码,但我认为这是您需要使用的缺失代码 "I notify the listener a changed" you almost answered yourself. You need to use the RecyclerView adapter's function notify ...
-
如果你的recyclerView是match_parent,你可以使用smth之类的 DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics(); float dpHeight = displayMetrics.heightPixels / displayMetrics.density; 所以你可以holder.mView.setheight(dpHeight/6); 另一种方式是 @Override pu ...
-
问题来自于 cardView = (CardView) rootView.findViewById(R.id.cardview1); 线。 因为带有R.id.cardview1 id的R.id.cardview1是RecyclerView行布局内部,但是使用rootView.findViewById试图从错误的布局fragment_friends访问它。 为了解决这个问题,将setOnClickListener添加到CardView里面的RecyclerViewAdapter类的onBindViewHol ...