Linq: additional parameter

I have the following line: orderBaseData.Single(o => o.Id == order.Id).OrderMessages.Count; I want to filter this a bit more. Each OrderMessage has a variable called hideFromUser, and I want to get the count of the OrderMessages where this is set to

How to convert this SQL statement to linq in C #?

Please help me to convert this SQL statement to Linq in C#: string cmd = "SELECT * FROM dbo.Personnel WHERE (dbo.Personnel.FName LIKE @FName + '%' AND dbo.Personnel.LName LIKE @LName +'%')"; if (objPPersonnel.PersonnelCode != 0) { cmd += "A

C # linq for the loop in the add method

Is it possible to use for loop inside the add method? This is my code and i want to add to each question four answers : for (int i = 0; i < 40; i++) { Questions.Add(new Question { QuestionString = GlobalClass.RandomString(40), Answers = new List<Ans

EF6: Use reference / search data with IQueryable

I want to use a pre-loaded lookup data from a list within a query. I need the query to return as IQueryable because it is used in a grid & being paged (not included here). I need the Labels to load from the lookup to avoid joins (more are in the actu

How to write dynamic LINQ queries using DBContext in C #

I am modifying my project to use DBContext instead of ObjectContext. My existing code var query = context.Vehicles.OrderBy("it.VehicleType.VehicleTypeID"). GroupBy("it.VehicleType.VehicleTypeID", "Min(it.ODO_Reading) AS MinRunVehi

Linq FirstOrDefault - a coating

i have the following code to determine a age from a Person var pList = ctx.Person.Where(x => x.Create > Date); int Age = pList.Where(x => x.ID == "foo").FirstOrDefault().Age ?? 20; I pick a Person by ID, if it doesn't exist the default

Xelement Linq with a null value?

I try getting all the Xelement value and insert into an array, however when the Xelement is null, it will show the error as below when insert into array: Object reference not set to an instance of an object. Is it possible to remove the null value? O

Join 2 tables with several references in LINQ

I have 2 tables, Table1 and Table2. **Table1** Id Name ------------ 14443 Michael 55658 Brian 84321 Lisa 335896 NULL 1035 Maya 5221296 Brenda **Table2** Id1 Id2 MatchLevel -------------------------- 14443 5221296 0,5192 14443 84321 0,8647 14443 18234

Using LinQ to filter ObservableCollection

I have a MVVM application and I am trying to make filtering through LinQ work on my ObservableCollection that is gotten from database based on Entity Framework. In View Model I have this: public class MenuListViewModel : BaseViewModelCollection<Menu>

Filter a list using except on multiple properties

I am trying to write a method which will ultimately give me a collection of records which no longer have a corresponding record within a different collection to which I am referencing. The structure is something similar to: public class A { int id {g

Compare 2 List & lt; chain & gt; with a LIKE clause

I have 2 lists, one a list of file names, the second a list of file name stubs, i would like to select everything from the first list where the file name is like the file name stub. List<string> files = new List<string>() {"a.txt", &

C # sort a list of strings by a list of doubles

I need to create a list of strings that represent the top five of the summed values. I have a database with hundreds of bills pertaining to different services ex. electric $600 January 2013 Water $50 January 2013 I need to sum all the same services w

Dynamically create GridView

I want to create a GridView that displays records for PDF Files. These records can have meta data attached that is customizeable by the user, so they can create their own columns and enter their own information in there. I then want it to be displaye

LINQ; how to register with max date with join?

How can I do this in LINQ? select * from customer c left join order o on o.CustomerID = c.CustomerID where o.OrderDate = (select MAX(OrderDate) from order where CustomerID = o.CustomerID ) not worried about dups as there will always only be one order

Where clause in .NET MVC

I have the following code that selects a bunch of comments from a database, but I only ever have one current post and I would like to deal only with comments regarding the current Post. public ActionResult Index() { ViewBag.PostCommentFK = new Select

NHibernate and Repository Template

What is the recommended approach to take with Nhibernate + Repository pattern? There are so many different articles and opinions around that I am not sure what path to take. Take this lengthy article, for example. It gives an example of Query objects

LINQ to Entities how to update a record

Okay, so I'm new to both EF and LINQ. I have figured out how to INSERT and DELETE but for some reason UPDATE seems to escape my grasp. Here is a sample of my code: EntityDB dataBase = new EntityDB(); Customer c = new Customer { Name = "Test", Ge

LINQ-to-SQL: search against a CSV file

I'm using LINQtoSQL and I want to return a list of matching records for a CSV contains a list of IDs to match. The following code is my starting point, having turned a CSV string in a string array, then into a generic list (which I thought LINQ would

Linq Sub-selection

How do I write a sub-select in LINQ. If I have a list of customers and a list of orders I want all the customers that have no orders. This is my pseudo code attempt: var res = from c in customers where c.CustomerID ! in (from o in orders select o.Cus