score:0
Accepted answer
The problem was indeed within the method GetCollection<>() once I replaced it with the following code, it worked just fine:
public MongoCollection<T> GetCollection<T>(string name = null)
{
string collectionName = name;
if (collectionName == null)
collectionName = typeof(T).Name;
if (Database.CollectionExists(collectionName) == false)
Database.CreateCollection(collectionName);
return Database.GetCollection<T>(collectionName);
}
score:0
You can also change it to something like
var usr = users.AsQueryable().Where(u => u.UserName.Equals(username)).FirstOrDefault();
Source: stackoverflow.com
Related Articles
- Either an issue with my linq statement or with my GetCollection<T>()
- Linq Join With Include Statement
- Linq Query with a Where clause in an Include statement
- List to Dictionary with incremental keys in one line LINQ statement
- How to introduce Let keyword inside Linq statement with Group by
- Unwieldy LINQ statement with multiple search criteria
- LINQ groupby statement with key
- Issue with dynamic LINQ queries containing brackets
- NHibernate 3 LINQ inner join issue with three jumps: NotSupportedException
- LINQ Source Code Available
- Use == operator with generic type in a Where Linq statement
- How to construct a having statement in linq with a max value?
- Issues with LINQ statement with defining an element of a collection
- Linq with where clause in many-to-many EF Code First object
- EntityFramework 6.1.1 with Linq Performance issue
- LINQ to SQL: Issue with concurrency
- LINQ Query with both CASE statement and SUM function
- A linq statement with multiple group by columns not allowing a thenby
- I'm trying to simplify with linq a statement that takes 2 lists of numbers and subtracts the first one from the second one
- Issue With LINQ and Reference List
- how to deal with exception in LINQ Select statement
- Programmatically building a query with LINQ statement with entity framework
- Linq statement with two where clauses
- Split list into two lists with single LINQ statement
- Entity Framework - LINQ statement with WHERE clause based on NULLABLE parameter
- C# - Linq optimize code with List and Where clause
- Select method missing from intellisense with Linq statement
- select from linq statement with await
- Linq statement with mutiple OrderBy clauses not working
- LINQ Join statement with possible NULL id?
- Selecting a matching ID from a list of objects
- C#: Func<> instead of methods?
- RavenDB full-text search dictionaries using IRavenQueryable
- recreate a LINQ to Entities query in DBO
- How can I create an Action<T> in F#?
- Linq query with multiple joins
- How can I debug or set a break statement inside a compiled expression tree?
- lambda using tuple via reflection
- How can i make a LinQ query using where and with an int[] list?
- WebAPI .getJSON function and querying a list with linq returning "Undefined"
- Improve LINQ query performance
- Custom Where expression
- C# return linq result as a list from a wcf service method then use it in aspx web forms page
- Convert xml to class using Linq
- C# IQueryable - How to query a list inside another list
- Linq SQL Distinct at server side or app side?
- Dynamic Linq OrderBy null error
- Whats wrong in this Linq query
- Removing a Dictionary Entry With a Regex
- How to change a returned null value in Linq to IQueryable