本文介绍了删除记录并将其添加到IQueryable LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我有一个小问题,也许有人可以帮助我.

我有一个IQuerable< subscription>我是从数据库中的表中填充的.我的问题是如何将子添加到IQuerable对象,即将Subscription类型的对象添加到IQueryable< subscription> ;?显然,以下代码来自应用程序的不同位置.

Hey guys, I have a small issue which maybe some one can help me with.

I have an IQuerable<subscription> which I populate from a table in the database. My question is how do I add the sub to the IQuerable object i.e an Object of type Subscription to the IQueryable<subscription>? Obviously the below code is taken from different places in the application.

//Declaration
IQueryable<Subscription> subscriptions;

//Populate
subscriptions = db.GetTable<Subscription>().Where(s => s.SubscriptionLinkTypeId == (byte)SubscriptionLinkType.Alarm);

 var sub = _lstOfSubscriptions.Where(
s => s.SubscriptionLinkId == subscriptionLinkId && s.SubscriptionLinkTypeId == subscriptionLinkTypeId && s.SubscriberLinkId == subscriberLinkId && s.SubscriberLinkTypeId == subscriberLinkTypeId && s.NotificationMethodId == notificationMethodId).First();



感谢您的帮助...



Thanks for your help guys...

推荐答案

IQueryable<Subscription> subscriptions;



//人口



//Populate

subscriptions = db.GetTable<Subscription>().Where(s => s.SubscriptionLinkTypeId == (byte)SubscriptionLinkType.Alarm);

 var sub = _lstOfSubscriptions.First(
s => s.SubscriptionLinkId == subscriptionLinkId && s.SubscriptionLinkTypeId == subscriptionLinkTypeId && s.SubscriberLinkId == subscriberLinkId && s.SubscriberLinkTypeId == subscriberLinkTypeId && s.NotificationMethodId == notificationMethodId);

subscriptions.ToList().Add(sub);



请勿同时使用Where和First.
_lstOfSubscriptions.Where.First == _lstOfSubscriptions.First()



Don''t use Where and First together.
_lstOfSubscriptions.Where.First == _lstOfSubscriptions.First()


List<subscription> subscriptions;</subscription>


然后,您可以将选定的 subs 添加到列表中.


Then you can add the selected subs to the list.

subscriptions.Add(subs);


然后您可以将其转换回通用IQueryable<subscription></subscription>


And then you can convert it back to generic IQueryable<subscription></subscription>

var newSubs = subscriptions.AsQueryable();


这篇关于删除记录并将其添加到IQueryable LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 20:15