score:2
Accepted answer
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;
}
}
score:2
private static void getuserdata(string username, usersession user)
{
using (entities ctx = commonsert.getcontext())
{
var result = (from ur in ctx.datuserroles
where ur.accountname.equals(username, stringcomparison.currentcultureignorecase)
select new
{
active = ur.active,
id = ur.id,
//...select all properties from the db
}).firstordefault();
if (result != null)
user.useractive = result.active;
user.userid = result.id;
//..set all properties of "user" object
}
}
Source: stackoverflow.com
Related Query
- LINQ Returning a set of results
- Trouble with LINQ Returning Results Set from Object[] Array Within Object
- Rules of thumb for when to call ToList when returning LINQ results
- linq query for varchar field not returning any results
- Linq join returning duplicate results
- DateTime comparison in LINQ not returning correct results
- LINQ Join not returning results if second or third table empty
- Order of execution of LINQ methods returning same results but different SQL in this code. What exactly is going on inside?
- Linq is returning too many results when joined
- Returning Most Relevant Search Results Using LINQ Where/Take
- Why is sql server query returning results and linq query is not
- MS Graph - LINQ query returning incorrect results
- Returning results of LINQ query
- LINQ query filters not returning correct number of results
- c# LINQ returning all joined results
- LINQ - get results where a certain property is in this other result set of the property's type
- Linq to SQL to return multiple counts from query not returning correct results
- Linq left outer join not returning results
- Linq to sql stored proc not returning results
- LINQ Union not returning wanted results
- Linq query with a Join, not returning the correct results
- LINQ query not returning expected results
- LINQ query returning null results
- Recursive linq results returning duplicates
- LINQ query not returning results that I expect
- LINQ query returning no results
- Linq PredicateBuilder not returning results
- LINQ query is not returning expected results
- Grouping set of results using linq in C#
- Returning LINQ row results to Array or List
More Query from same tag
- c# linq 'potentially' grouping and differences
- Linq: GroupBy vs Distinct
- Parse boolean condition into expression tree
- IList<Object> to XML via a ForEach
- What is the best data access paradigm for scalability?
- LINQ XML - Select all parent elements where a child has a given value
- C# XElement is not getting multiple Values for the same Tag multiple times
- how to use left join in linq
- Concatenate strings inside a linq 'select new object {
- LINQ: Sum from M-M table
- How do I use LINQ to update a datatable with a SqlDataReader?
- Return certain record based on criteria (2)
- How to embed a JavaScript in a LINQ expressionin Razor?
- Filtering ListBox using combobox and LINQ
- Join two lists without having any matching columns in LINQ
- EFCore Querying by a Null Navigation property
- Linq Group by Month, Aggregate count
- How to use Linq to group every N number of rows
- Remove items from list using their IDs and linq
- How Do I Create an Expression<Func<>> with Type Parameters from a Type Variable
- Linq To Sql compare Time only
- Linq-to-sql join/where?
- ConfigurationElementCollection LINQ
- Linq - Dynamic Condition
- Order query Results by Enum Name
- Compare generic Collection?
- Create and insert from Temporary table using Linq to SQL in DBML
- Need help with a LINQ ArgumentOutOfRangeException in C#
- Is it possible to serialize a grouped list?
- How can I generate this property implementation using Expressions instead of emitting IL?