linq

Given UIElementCollection, find all elements that have StyleA, and change them to StyleB in WPF

I've got a MyGrid.Children UIElementCollection, I would like to find all the Rectangles in it that have there styles set to StyleA, and set them to StyleB. I'd like to use LINQ if possible, so I can avoid a nasty nested loop. Something like this pseudocode: var Recs = from r in MyGrid.Children where r.Style == Styl...

How do C# Linq extension methods perform equality comparison?

So, the following lambda expression is not returning any elements in the collection, even though while stepping through I was able to verify that 1 item matches the criteria. I've added a sample of the class with it's IEquatable implementation. ...within a method, foo is a method parameter var singleFoo = _barCollection.SingleOrDefault(...

Grouping Values With C# And LINQ

I have a LINQ question. Let's say I have a database with the following values: =================== Date,product,orders ------------------- 1/2/2003,apple,3 1/2/2003,orange,5 1/3/2003,orange,6 1/4/2003,grape,2 =================== How can I use LINQ to get a result that groups the items by date and puts them into a variable that looks ...

Most popular GroupBy with Linq to Entities

I have a standard store schema with an InvoiceLine table that contains Products. I'd like to get a list of the top 5 products by sales as a List. What's the cleanest way to do that? This can't be the best way: private List<Product> GetTopProducts(int count) { var topProducts = from invoiceLine in storeDB.InvoiceLines ...

NHibernate.Linq, WCF RIA Services, weird error.

Hi all. I have a Silverlight Business Application project set up, with these codes. I have this domain class: public class BaseDomain { public virtual Guid Id { get; set; } public virtual DateTime CreatedOn { get; set; } } public class Sector : BaseDomain { public virtual string Code { get; set; } public virtual string...

IEqualityComparer meaning

Consider this array string[] presidents = { "Adams", "Arthur", "Buchanan", "Bush", "Carter", "Cleveland", "Clinton", "Coolidge", "Eisenhower", "Fillmore", "Ford", "Garfield", "Grant", "Harding", "Harrison", "Hayes", "Hoover", "Jackson", "Jefferson", "Johnson", "Kennedy", "Lincoln...

Is this LINQ dynamic orderby method thread safe?

Hello After searching online and going through past stackoverflow posts for a suitable implementation for dynamic ordering with linq, i came up with my own implementation that borrows a few things from other solutions i have previously seen. What i need to know is if this implementation is threadsafe? I don't believe it is as i am pas...

Linq to SQL Associations with fixed fields

Linq to SQL, in the dbml designer (or otherwise) I have 3 tables: Orders, Deliveries and EmailTemplates. Orders have many Deliveries, and Orders and Deliveries have a status (int) field. EmailTemplates have a status they apply to and a bool IsForDeliveries field. I have Linq to sql associations for Order->EmailTemplate on order.st...

Strange result with string comparison in LINQ

I have a XML source with nodes like this (Somewhat anonymized): <XXX> <Code A="oa ">01</Code> <Name A="oa ">Card</Name> <F1 A="oa ">x</F1> <F2 A="oa ">y</F2> <F3 A="oa ">z</F3> </XXX> I load the XML-document into a XElement and query it with linq var query = from creditcard in xml.Descend...

Why no intellisense when LINQ statement has no where clause?

Can anyone tell me why I do not get intellisense with this code: var testDocuments = (from u in db.TestDocuments orderby u.WhenCreated descending select u). but I do get intellisense with this code: var testDocuments = (from u in db.TestDocuments orderby u.WhenCreated des...

Understanding the delete link in ASP.NET Dynamic Data scaffolds.

Since the automatic scaffolding of ASP.NET Dynamic Data Web Pages does most of the things I need to do for this project on its on, I'd like to use it as a basis. Now, I like to add another link to the "Edit" "Delete" "Details" trio on my custom table view. I'd like it behave much like the "Delete" button, i.e. not call another page, but...

Excel to xml conversion not working for columns with different datatype values starts from number to string.

I am facing a problem while reading the excel and writing them to XML using LINQ to XML. I am having a column name as PinCode which has values like 9999 12 "123" "20" "999" 3 While converting the excel to dataset I have the values 9999,12,3. I am not able to retrieve the values in string format. I dont want to change the formats in ex...

LINQ to Entities does not recognize the method ElementAt(i);

Hi, i'm using the method elementat for get a specific element of a query's result. var mds = db.TDP_MissioniDestinazioni.Where(p => p.MissioneID == missioneRow.MissioneID); destinazioneRow = mds.ElementAt(i); LINQ to Entities does not recognize the method 'TimeEntModel.TDP_MissioniDestinazioni ElementAt[TDP_MissioniDestinazioni](S...

Entity Framework Persisting local scope variable?!?!?

Hello guys I have the following method: var usuario; usuario = UniapontaService.GetUsuarioUniapontaPlanejamentoEstrategico(x => x.IdUsuario == VWUsuarioUniaponta.IdUsuario && x.PlanejamentoEstrategico.IdPlanejamentoEstrategico == HorarioTrabalhoCorrente.PlanejamentoEstrategico.IdPlanejamentoEstrategico...

C# - convert anonymous type to observablecollection

Hello, I have a LINQ statement that returns an anonymous type. I need to get this type to be an ObservableCollection in my Silverlight application. However, the closest I can get it to a List myObjects; Can someone tell me how to do this? ObservableCollection<MyTasks> visibleTasks = e.Result; var filteredResults = from visibleTask i...

What happens when LINQ updates fail?

Here's the scenario: Process 1 (P1) - reads in various flat files one consequence of which is deleting or adding photos URLs to a database table to indicate that these need to be downloaded Process 2 (P2) - Looks up the photo URLs that need to be downloaded, actually performs the download, then marks the record as downloaded P1 and P...

LINQ - 100 Views - Same Columns - Generic Queries

Hello, Here is my scenario: We have a legacy system that has about 100 views that all pull the same columns worth of data. Now, in my DataContext I have all the views in the context and I have a seperate query from each one. Each query's results loads into a single List that gets returned to the application. Is it possible to have a s...

using Comparer to sort IEnumerable in C# by different fields

I have a list of an object which need to be sorted depending on three different properties of the object. Example CLass Object1{ Property1 , Property2, Property3} ListObj = IEnumerable<Object1> Foreach ( item in ListObj){ if (item.Property1 == true) item goes at top of list if(item.Property2 == true) item goes e...

linq strange error with null

i have function public List<Menu> List(int? parentId) { return (from i in _dataContext.Menu where i.Menu2.Id == parentId select i).ToList(); } if i pass in function parameter null (like List(null)) it search nothing, but if i put null in query like this return (from i in _dataContext.Menu where ...

Is there any consideration while comparing Enums in LINQ-to-NHibernate or LINQ?

In such a query: var q = from l in session.Linq<Letter>() where letterTypeSearch == null ? true : (l.LetterType.ToString() == letterTypeSearch) l.LetterType is an Enum. UPDATE It seems that's impossible to compare Enums in current linq-to-nhibernate. While letterTypeSearch is a string containing a LetterType instance...