---
title: "LINQ Returning a set of results"  
description: "LINQ Returning a set of results"  
author: "Anonymous User"  
published: 2014-08-29  
updated: 2014-09-01  
canonical: https://www.mindstick.com/forum/2207/linq-returning-a-set-of-results  
category: "asp.net"  
tags: ["asp.net", ".net", "c#", "LINQ Returning a set of results", "linq"]  
reading_time: 1 minute  

---

# LINQ Returning a set of results

i have some code that sets user's [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) like so:

us = new UserSession();

us.EmailAddr = emailAddr;

us.FullName = fullName;

us.UserROB = GetUserROB(uprUserName);

us.UserID = GetUserID(uprUserName);

us.UserActive = GetUserActive(uprUserName);

where GetUserROB, GetUserID and GetUserActive all look similar like so:

[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) GetUserActive(string [userName](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username))

{

using ([Entities](https://www.mindstick.com/blog/250/html-character-entities) ctx = CommonSERT.GetContext())

{

var [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) = (from ur in ctx.datUserRoles

where ur.AccountName.Equals(userName, StringComparison.CurrentCultureIgnoreCase)

[select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) new

{

[Active](https://answers.mindstick.com/qa/97113/why-does-an-active-ftp-not-work-with-network-firewalls) = ur.active

}).FirstOrDefault();

if (result != null)

return result.Active;

else

return "N";

}

}

it works, but i dont think it's the right way here. how can i assign userROB, ID and Active properties all in one LINQ call? without having to have 3 separate [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing) to do this?

## Replies

### Reply by Sumit Kesarwani

try this:

```
private static void GetUserData(string userName, UserSession userSession){    using (Entities ctx = CommonSERT.GetContext())    {        var result = (from ur in ctx.datUserRoles                     
where ur.AccountName.Equals(userName,StringComparison.CurrentCultureIgnoreCase)                     
select new                     
{                         
UserActive = ur.active,                         
UserROB = ur.ROB,                         
UserID = ur.ID                     
}).FirstOrDefault();    }    if (result !=null) {       
userSession.UserActive = result.UserActive;       
userSession.UserROB  = result.UserROB;       
userSession.UserID = result.UserID;    }}
```


---

Original Source: https://www.mindstick.com/forum/2207/linq-returning-a-set-of-results

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
