Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
//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...
Posted
Updated 19-Aug-13 5:18am
v3

You should first convert it to List.IQueryble does not have a method for adding
//Declaration
C#
IQueryable<Subscription> subscriptions;


//Populate
C#
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);


Don't use Where and First together.
_lstOfSubscriptions.Where.First == _lstOfSubscriptions.First()
 
Share this answer
 
Comments
frostcox 19-Aug-13 11:44am    
Thank you kind sir, will calling the to list on the IQueryable subscription affect when I call db.GetChangeSet??
Jameel VM 19-Aug-13 12:35pm    
you can also convert list to iQueryble also
Easiest way is to use generic List<t></t> which implements IList.
C#
List<subscription> subscriptions;</subscription>

Then you can add the selected subs to the list.
C#
subscriptions.Add(subs);

And then you can convert it back to generic IQueryable<subscription></subscription>
C#
var newSubs = subscriptions.AsQueryable();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900