linq

Is it possible to databind directly from a linq query result to a control?

I have just started using WPF and am having trouble data binding from the result of a Linq query to a ListView. I have tried a number of combinations including setting the DataContext and ItemsSource to the query. As in: listView.DataContext = (from person in People select person).ToList(); Then in the xaml setting the DisplayMemberB...

Linq & String.ToLower() strange behavior

Hi! I have a query on the server side that returns a list of distinct cities from a zipcode table. I'm using WCF RIA Service. The following query successfully returns 228 cities when provincename == "" public IQueryable<CityPM> GetCities(string provinceName) { return this.ObjectContext.ZipCodes.Where(z => z.Province.Cont...

LINQ & IEnumerable<String> Re-evaluation

Good morning, I wrote the following LINQ query public static Func<String, IEnumerable<String>> ListaCorreccoes = (StrPalavra) => { return (from StrTmp in ListaPossiveisCorreccoes(StrPalavra) from StrTmp2 in ListaPossiveisCorreccoes(StrTmp) where PalavraConhecida(StrTmp2) sel...

how to retrieve from xmldocment as xml node using linq

i like to retrieve datas from xml file using linq. i verified lot of examples ,all examples shows retrieved element in the form of XElement but retrieve in the form of XMLNode. is it possible to do like that else how can i convert XElement into xmlnode ,how can i do this.i need it in XMLBound Element not in XMLDocment. ...

NH Linq with FetchMany and ToFutureValue in NH 3.0.0beta

I'm trying to use the ToFuture with the new NH Linq 3.0 provider. This works fine: var result = ses.Query<Parent>() .Where(x => x.Id == id) .ToFutureValue(); but when I use a Fetch/FetchMany like this: var result = ses.Query<Parent>() .Where(x => x.Id == id) .Fetch(x =...

Entity Framework 4 generated queries are joining full tables

Hello, I have two entities: Master and Details. When I query them, the resulting query to database is: SELECT [Extent2]."needed columns listed here", [Extent1]."needed columns listed here" FROM (SELECT * [Details]."all columns listed here"... FROM [dbo].[Details] AS [Details]) AS [Extent1] LEFT OUTER JOIN [dbo].[Master] AS [Extent...

How to get an outerjoin on a Linq query

Given this linq query from c in context.Customers from o in c.Orders where c.City == "MyCity" || o.ShipTo == "MyCity" select c the query will not return any rows if the customer's city is "MyCity" but does not have any orders. This is because of the implied inner join between Customers and Orders. How do I select customers with a Ci...

How do I update Linq intellisense when I alter my table?

Suppose I make a change to a sproc or a Table that would require me to update previously generated Linq statements. How do I refresh this auto-generated code? ...

LINQ with existing databases and unknown schema

I'm working on a database heavy project, where the Microsoft SQL databases are very mature (16 or more years-old mature), and an old product uses VB6 and ADO to generate sql which interacts with the database. I've been given the task of porting/re-writing the ancient version with a new .NET version. I'd love to use LINQ-to-* to ensure ...

Linq to EF Search for a string that does not start with a Letter

I am using Linq to Entity Framework 4, what I'm trying to do is build a query that finds all supplier entities that do not start with a letter, typically these are numbers, e.g. "1st Choice" I thought this would be trivial and wrote this: var letters = Enumerable.Range('A', 26).Select(x => (char)x); var results = from supplier in All() ...

WCF service returns null for a column in SP

I have a stored proc where one of the columns is sum(Value)/sum(qty) * sum(Requested) as ValueReq Value, qty and Requested are columns of a table with datatype as numeric(20,0) in sql server. In the linq to sql class, ValueReq is declared as private System.Nullable<decimal> ValueReq Although the query returns non zero values as r...

How would I write this dynamic linq query?

Hi all, Basically I want to write a linq query to order the number of days they were present. But I have got these six time filters- Today,Yesterday,current month,previous month,current year,previous year.So now I have this queries which I have simplified but before these queries below, I actually order these employees on different aspe...

C# word boundary regex instead of .Contains() needed

I have a list: var myList = new List<string> { "red", "blue", "green" }; I have a string: var myString = "Alfred has a red and blue tie"; I am trying to get a count of matches of words in myList within myString. Currently, I am using .Contains(), which gets me a count of 3 because it is picking up the "red" in "Alfred". I need to...

LIKE with Linq to Entities

I know the .Contains() method does like LIKE %therm%, the .StartsWith() method does like LIKE therm% and the .EndsWith() method like LIKE %therm but... Is there a way to do like below on **Linq to Entities**? SELECT * FROM [dbo].[Users] WHERE Name LIKE 'rodrigo%otavio%diniz%waltenberg' PS: I'M USING LINQ TO ENTITIES. NOT LINQ TO SQL ...

Need help with merging two data collections

Hello! I need to retrieve all items from two lists that contains a given value. Example: var list1 = { new Dummy(){ Name = "Dummy1", Number = 1 }, new Dummy(){ Name = "Dummy2", Number = 2 }, new Dummy(){ Name = "Dummy3", Number = 3 } }; var list2 = { new Dummy(){ Name = "Dummy4", Number = 4 }, new Dummy(){ Name = ...

Is it possible to use existing classes as POCOs in Entity Framework

Hi, I was able to generate pocos using POCO template from Microsoft. It works great. My question is how I could modify this or any other template to use existing objects from a different assembly, and just load data into them. The way i tried going about it, was to create POCO's using the template, and the PocoGenerator.Context to ...

Dynamic LINQ help for sorting problem

I have a simple IEnumerable collection of Order objects. I want to write a generic sort function that accepts the collection and a sortkey that corresponds to a property on an Order object. I don't want to hardcode the sort instructions for every property. How can I build a dynamic LINQ string that automatically generates the LINQ for me...

How can I force LINQ to SQL to perform an INNER JOIN on a nullable foreign key?

I have a very simple set-up. Table "Node" has a nullable foreign key "ObjectId." This is represented in my database model with a one-to-many association. Now, I want to run a query that gives me all Node-Objects with a particular object id. In straight SQL, this is very easy: SELECT Node.*, Object.* FROM Node INNER JOIN Object O...

Xpath best practices

Hello there, I have a readonly xml file and I have a set of xpath values. I need to create a function which would take in the xpath and return the value(s) corresponding to the xpath. I am a little confused regarding what would be the best way to proceed. The options I am thinking are using the regular XPathDocument/Navigator/Iterator ...

Remove overlapping items between two List<string> collections

I have two collections of List, let's call them allFieldNames (complete set) and excludedFieldNames (partial set). I need to derive a third List that gives me all non-excluded field names. In other words, the subset list of allFieldNames NOT found in excludedFieldNames. Here is my current code: public List<string> ListFieldNames(List<st...