linq

Using Linq on a Dataset

Can someone enlighthen me with regards to Linq please? I have a dataset that is populated via a SQL Stored Procedure, the format of which is below: Country | Brand | Variant | 2004 | 2005 | 2006 | 2007 | 2008 The number of rows varies between 50 and several thousand. What I'm trying to do is use Linq to interrogate the dataset (there...

c# syntax and Linq, IQueryable

Hello. This is a question about the SYNTAX of c# and NOT about how we call/use IQueryable Can someone please explain to me: We have this declaration (System.Linq): public static double Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int>> selector) and to call the Aver...

How to detect if a LINQ enumeration is materialized?

Is there some way of detecting whether an enumerable built using LINQ (to Objects in this case) have been materialized or not? Other than trying to inspect the type of the underlying collection? Specifically, since enumerable.ToArray() will build a new array even if the underlying collection already is an array I'm looking for a way of ...

Help me with LINQ to entities query, please

I need to build a query to the entities to get records including: AssetWeapon, PersonOut number of records with IsIn = True, number of records with IsIn = False, name of the month of StartTime, Records should be grouped by AssetWeapon thank you guys! ...

ASP.Net Using LINQ SQL as a Counter

Is there a better way to use LINQ to act as a counter each time a button is pressed? Seems like there should be a better way then having a LINQ statement run and get the current value and then an addition statement to insert the old value + 1. ...

Wherewith replace Dictionary.Where(p => p.Key is T)

I have a System.Collections.Generic.Dictionary<System.Web.UI.Control, object> where all keys can be either type of System.Web.UI.WebControls.HyperLink or type of System.Web.UI.WebControls.Label. I want to change Text property of each control. Because HyperLink doesn't implement (why??) ITextControl, I need to cast Label or HyperLink exp...

Using LINQ, need help splitting a byte array on data received from Silverlight sockets

The message packats received contains multiple messages deliniated by a header=0xFD and a footer=0xFE // sample message packet with three // different size messages List<byte> receiveBuffer = new List<byte>(); receiveBuffer.AddRange(new byte[] { 0xFD, 1, 2, 0xFE, 0xFD, 1, 2, 3, 4, 5, 6, 7, 8, 0xFE, 0xFD, 33, 65, 25, 44, 0xFE}...

Linq query with subquery as comma-separated values

In my application, a company can have many employees and each employee may have have multiple email addresses. The database schema relates the tables like this: Company -> CompanyEmployeeXref -> Employee -> EmployeeAddressXref -> Email I am using Entity Framework and I want to create a LINQ query that returns the name of the company...

Mixing LINQ to SQL with properties of objects in a generic list

I am trying to accomplish something like this query: var query = from a in DatabaseTable where listOfObjects.Any(x => x.Id == a.Id) select a; Basically, I want to filter the results where a.Id equals a property of one of the objects in the generic list "listOfObjects". I'm getting the error "Local sequence cann...

Displaying text in C# from XML via LINQ

Is there a way to display "Test" value as bold just like the implementation of newline? <testElement>Test &#xD; Test</testElement> The output of the above line when you display it is: TEST TEST I want to know what/how to make the second line as bold just line by using expressions. Thank you ...

LINQ to XML, Retrieving in the right order the rigt nodes.

Have you ever had one of those days when you've dug a hole but your so deep in now that the only option is to keep on digging and see where you come out? I thought just for giggles in the latest component I'm writing to use LINQ to XML because it was about time I saw what all the hooplah was about. The Problem: I am generating an XML ...

Linq EntityState Problem..

Hello How can I change EntityState from NotTracked to Modified of my CurrentEntity. I mean I do modify my CurrentyEntity but the EntityState shows NotTracked where it should be Modified. What could be reason behind this..? ...

Export to Excel in linq

We are doing an File management project We need a same excel format Please help me to do the same ...

List<T>.SelectMany(), Linq and lambda help

Hi there I have a class. public class MedicalRequest { private int id private IList<MedicalDays> Days private string MedicalUser ... } and another public class MedicalDays { private int id; private DateTime? day private MedicalRequest request ... } I'm using nhibernate to return a list of all t...

linq and contains

i have func public PageOfList<ConsaltQuestion> Filter(int? type, int pageId, EntityCollection<ConsaltCost> ConsaltRoles) { // return _dataContext.ConsaltQuestion.Where((o => o.Type == type || type == null) && (o=>o.Paid == paid)); return (from i in _dataContext.ConsaltQuestion where ((i.Type == type || type == null) &...

C#: access a class property when the property identifier is known as a string

Hi, I'm using LINQ to Entities on a database which structure is not known in advance. I use reflection to retrieve the information, and now have a list of strings with all the table names. Because I use LINQ, I also have the datasource encapsulated in a C# class (linqContext), with each table being a property of that class. What I want...

data is not getting ordered by date

Can't get list sorted by date. How to show data ordered by date? XDocument doc = XDocument.Load(Server.MapPath("file.xml")); IEnumerable<XElement> items = from item in doc.Descendants("item") orderby Convert.ToDateTime(item.Attribute("lastChanges").Value) descending ...

How to pick a specific object from a Linq Query using Distinct?

I have a list with two or more objects of class Agent. Name = "A" Priority = 0 ResultCount = 100 ; Name = "B" Priority = 1 ResultCount = 100 ; Both objects have the same ResultCount. In that case I only need one object and not two or more. I did this with a Linq Query with Distinct and an custom made Comparer. IEnumerable<Agent...

What is the best way in assigning foreign key when using entity framework & LINQ to Entities?

Hi all, I need to know the best practice of creating an entity object and assigning the foreign key. Here is my scenario. I have a Product table with pid,name,unit_price etc.. I also have a Rating table with pid (foregin key),rate,votes etc... Currently i am doing the following to create the rating object: var prod = entities.Product....

how to fill missing values from a list

I have an object containing a date and a count. public class Stat { public DateTime Stamp {get; set;} public int Count {get; set ;} } I have a Serie object that holds a list of thoses Stat plus some more info such as name and so on... public class Serie { public string Name { get; set; } public List<Stat> Data { ge...