linq

Method with Predicate as Parameter

This is a general question, but here is the specific case I'm looking for a solution to: I have a Dictionary<int, List<string>> I want to apply various predicates to. I want one method that can take care of multiple LINQ queries such as these: from x in Dictionary where x.Value.Contains("Test") select x.Key from x in Dictionary where ...

XDocument to dataSet, my nested nodes are getting treated as new tables?

When looping through elements it thinks the child node is a table, when it should just be a column. I have most of the code working well, until I the code gets to this part: (all of my code is at the bottom) new XElement("TBL_Magic_TripCountries", lstCountry.Items .Cast<ListItem>() ...

Code clarity for converting generic list?

This code should convert the list of listType2s (list) to a list of type1s. I feel the functionality is somewhat difficult to ascertain though. I am looking to see alternative methods that are easier to read, yet concise, and brief. List<Type1> type1s = new List<Type1>(); listType2s.ForEach(t => type1s.Add((new Type1(t...

Convert nested type in C# using delegates / LINQ

How can I convert a List<List<string>> to a List<string[]> in C# in a concise way using delegates/LINQ? ...

LINQ to Entity RIA Query syntax?

I am using RIA services with Entity Framework- I have the following sql select statement: select * from TaskTable t, MapTable mt where mt.SiteID=1 and t.EndPointID=mt.EndPointID How do I write this using method queries and lamda, or any other way I can use in my domain services? All the examples I see return a new object- do I really ...

linq equals override

Can somebody help me to override equals operator in C# linq? This is the problem: var temp = from t1 in table1 join t2 in table2 on t1.column1 equals t2.column2 select t1.column4; it is worth mentioning that t1.column1 and t2.column2 are actually some specific types. If anyone needs more information, please let me know. Tnx ...

Foreign Keys in ASP.NET Data Controls

I have been using LINQ with ASP.NET to build some quick and simple maintenance forms using detailsview component. However it gets more difficult when you have to insert/maintain foreign keys. I managed to make to work following ScotGu's tutorial with a dropdownlist or textboxes and a second LINQ data component to display meaningful infor...

Linq and Dictionary and converting array values

Hello, I have the following code IDictionary<string, IEnumerable<Control>> I need to convert it to IDictionary<string, IEnumerable<string>> using ClientID as the new value. Does anybody know how to do this in Linq instead iterating through the dictionary? Thanks Podge ...

Pivot in LINQ using lambda expression

I am writing a lambda in linq for getting the pivoted data from the resulting list.For getting the pivoting columns am setting a where condion to get the value.the problem here is am getting default value if the where condtion fails.I dont want the column if the where condition fails.Kindly help me out. var query = dataList .GroupBy...

Selecting a property based on Name in Linq projection

I have a class say public class CostStore { int DirectorateId { get; set; } decimal NewCar { get; set; } decimal ContractorNew { get; set; } decimal ContractorRenew { get; set; } decimal ContractorLost { get; set; } decimal ContractorStolen { get; set; } decimal InternalNew { get; set; } decimal ...

C# linq dates between

Hi I am tring to get a list of dates from my db that will eventually be used to populate a calendar. Each 'calendar event' has a start date & end date, i need to get all dates between & including the start & end date. i am stuck on the WHERE statement, as i am not sure what to use for this public List<EventFeed> GetCalendarDates() ...

How to bind AspxMenu by .xml file value

XElement xml = new XElement("contacts", from c in db.Categories orderby c.CategoryID select new XElement("contact", new XAttribute("contactId", c.CategoryID), new XElement("firstName", c.CategoryName), new XElement("lastName", c.Desc...

LEFT OUTER JOIN in LINQ

How to perform left outer join in C# LINQ to objects without using join-on-equals-into clauses? Is there any way to do that with where clause? Correct problem: For inner join is easy and I have a solution like this List< JoinPair> innerFinal = (from l in lefts from r in rights where l.Key == r.Key select new JoinPair { LeftId = l.Id,...

Linq Where Clause - Accessing a tables column name.

Hello all, I need a bit of inspiration from somewhere and hoping someone, anyone could help. This stems from a previous thread i created whereby I want to be able to do a autocomplete search on a complete data table i.e. all the data from all the columns. I have created a stored procedure that pulls together the autocomplete items and...

Comparing two collections

i have what seems like a common problem / pattern. two collections of the same object. The object has a number of properties and some nested objects within it. Car has a property called id which is the unique identifier. I want to find the LINQ way to do a diff, which includes: Items in one collection and not the other (visa versa)...

Select top 5 from a merged list (MVC)

I have two lists that have been merged. After a order by linq statement, I would like to select the top 5 from that complete list. I was thinking about using the linq statement to pick the top 5 from the list. var ListSort = from list in NewList orderby list.EntryDate select list;//Tried to select the top 5 from here Any other sug...

If Entity Framework is meant to work with POCOs, then why the dependency on IObjectSet?

I keep hearing about EF 4.0, POCO, IObjectSet, UnitOfWork (by the way, UoW is atleast more than 17 years old when I first heard it) etc. So some folks talk about Repository "pattern". etc. There are numerous bloggers showcasing their concoction of a "wrapper" or repository or something similar. But they all require IObjectSets (or in so...

Casting an Anonymous type to a known type.

I have a method that contains the following Linq to SQL code: public List<L2SBusinessEntities.Report.MesReport> GetListForReportTree(MESProductionDatabase database) { byte[] byteArray = new byte[1]; var results = from report in database.MesReport select new { report.MesReportID, report.Parent...

Linq join where ?

Hi. I got: entity1 - ID, OwnerCode entity2 - OwnerCode, DepartmentCode Also I have some DepartmentCode Now i want get something like this(sql syntax): Select e1.ID from entity1 e1 join entity2 e2 on e1.OwnerCode = e2.OwnerCode and e2.DepartmentCode=7 via Linq I wrote: var q = from e1 in entityes1 join e2 in entit...

What is an easy way to append or prepend a single value to an IEnumerable<T>?

I need to prepend a single value to an IEnumerable (in this case, IEnumerable<string[]>). In order to do that, I'm creating a List<T> just to wrap the first value so that I can call Concat: // get headers and data together IEnumerable<string[]> headers = new List<string[]> { GetHeaders() }; var all = headers.Concat(GetData()); Yuc...