linq

Selecting multiple table values and binding the data into multiple grids

Hi Everybody. I have multiple tables . I have created one stored procedure where I am selecting the table values. like create proc myProc as select col1, col2, col3 from table1 select cola, colb, colc from table2 select colp, colq, colr from table3 select colx, coly, colz from table4 I am using ...

How to use IQueryable types in DataGridViewColumnCollection in WinForm

I want to set DataGridView's columns to ReadOnly except one or two columns. I was trying to do this. dgv.Columns.AsQueryable().ForEach(col=>col.ReadOnly=true); But I found that these extension methods are not available at DataGridViewColumnCollection How can I do the same by this way ...

Linq Group by having

i'm new to linq, what i want is to do group by with having like in tqsl. my class: class test{ public int field1; public int field2; public int field3; } now i have: IEnumerable<test> list; i want something like: IEnumerable<test> q= from p in list group p by p.field1 having p.field2==p.field2.Max() select p; Can u help me? ...

How does LINQ's "Where" method works?

Exactly how LINQ's "where" method is defined? I'm guessing implementation is something like this: public static IEnumerable<T> Where ( this partialParent, Func<bla,bla> myDelegate ) Now if I invoke Where method like this: from c in context.Con where ( c.Col1 == c.Col2 ) select c I'm guessing "c.Col1 == c.Col2" is passed down and s...

Can any help me in writing the LINQ Query ?

I have a solution folder in which i have collect all the .dll's and store in a array list.I have to search all the sub-directories.Please help in writing the LINQ Query. var r = dir.GetFiles("*.dll").Where<FileInfo>(i => i.Name.StartsWith("SAMPLE")).ToList(); Is this Correct?For example i 20 dll's startwith name "SAMPLE" ...

linq to sql join result

I have two tables, with foreign key. linq to sql class generated for me classes. now i want make linq select with join, what will be result of join? is where any way to generate class, for that result? want get something like IEnumerable<par_of_class1+part_of_class2>. thx ...

LINQ - how to make change tracking work when entity passed to another class as property

Here's the scenario: I have an ASP.NET user control that runs a LINQ query, stores the results in a generic List, then dynamically loads another user control (into a Placeholder) and passes one of the objects from the List to the control through a property on the control. The child control displays data from the object and allows the u...

truncate text using linq

Looking for a simple query to truncate text by x amount of characters using Linq. ...

Dynamic LINQ API with .NET Framework 4

Is Dynamic LINQ API (released with the CSharpSamples), still the way to go, or is there a different / alternative approach with .NET 4 (and EF 4)? ...

Is there a LINQ query that will give me the sum of several maximum values?

I've got a table of transaction data for several locations and I need to find the sum of each location's maximum from a subset of locations. So imagine the following table: location year transactions 123 2009 57 124 2009 23 125 2009 45 123 2010 64 124 2010 12 125 2010 6...

How to create a method that suport translation to sql?

Hi, I wanted to use a method I created inside a query coz i need to implement a peculiar type of filter... return manager.Clients.SelectAll().Where(cli => cli.Name.SatisfyFilter(filter.Name) && cli.LastName.SatisfyFilter(filter.LastName) && cli.MiddleName.SatisfyFilter(filter.MiddleName)).ToList(); But i get the: "Method 'Boolean Sa...

Entity Framework LINQ projection into custom type results in missing data

I have a many to many relationship between Contractors and SafetyCouncils. They are joined by a bridge table ContractorsSafetyCouncils which consists of ContractorId and SafetyCouncilId. These 2 columns form a composite key. This relationship is mapped correctly in EF4. The Contractor entity has the property: public virtual ICollection<...

LINQ count character apperance

Instead of looping over my string I'd like to use LINQ. How to do the following? // explode our word List<char> rackBag = new List<char>(); rackBag.AddRange("MYWORD??".ToCharArray()); // How many wildcards? int wildCardCount = rackBag.Count(x => x.Equals("?")); wildCardCount should equal 2. ...

Filter a collection with LINQ vs CollectionView

Hello, I want to filter a ObservableCollection with max 3000 items in a DataGrid with 6 columns. The user should be able to filter in an "&&"-way all 6 columns. Should I use LINQ or a CollectionView for it? LINQ seemed faster trying some www samples. Do you have any pro/cons? UPDATE: private ObservableCollection<Material> _materialLi...

C#: Altering values for every item in an array

I'm wondering if there is built-in .NET functionality to change each value in an array based on the result of a provided delegate. For example, if I had an array {1,2,3} and a delegate that returns the square of each value, I would like to be able to run a method that takes the array and delegate, and returns {1,4,9}. Does anything lik...

LINQ to SQL default values

We all know that Linq to SQL (and SQLmetal/exe) is really a "prototype" quality product (it's missing basic features like schema "refresh" and detection of null columns with default value). Is there a way to automatically create my .dbml (similar to LINQ to SQL or SQLmetal) AND have it detect NOT NULL columns that have a default value? ...

LINQ Grouping help

I have a database table that holds parent and child records much like a Categories table. The ParentID field of this table holds the ID of that record's parent record... My table columns are: SectionID, Title, Number, ParentID, Active I only plan to allow my parent to child relationship go two levels deep. So I have a section and a sub...

Rx: EnumerableEx.For() vs Enumerable.SelectMany()

System.Interactive.dll includes a For() method with the following implementation: IEnumerable<TResult> For<TSource, TResult>( IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> resultSelector) { return source.Select<TSource, IEnumerable<TResult>>(resultSelector).Concat<TResult>(); } Am I missing something or ...

Linq Group By With Having

Here is my example: class test{ public DateTime dt; public double value; public int id; } i have: IEnumerable<Test> TestList; I want select rows from it, with group by id, with max(dt). my query: var q = from p in TestList group p by p.id into g select new { id = g.Key, dt = g.Max(w => w.dt) })...

How can i select specific childnodes with LINQ?

I have a node and this node contains 5 childnodes. three of them is RatePlan. How can i select those RatePlan childnodes with LINQ? Lets clarify something : my xml is like this : <hotels> <hotel id="1" name="hotel 1"> <telephone>123456789</telephone> <fax>123</fax> <address>hotels address</address> <hotelRatePlan>10<...