linq

How to convert System.Data.Linq.Binary to a Stream?

Thought I could use the BinaryWriter but haven't had any luck. Suggestions? ...

LINQ : Group by Multiple Columns and Count

I have Table1 and Table2 in the form of IEnumerable. Both the tables have columns Column1 and Column2 I would like to do a left outer join on Column1 and would like to get a count of the rows present in Table2 and load the records into a DataTable. I tried the following query var query = from p in Table1 join q in...

Apply dynamic where clause to joined table

I need to build a LINQ query that allows me to vary the where clause on a joined table but can't find a way to do it. A simplified example of the two queries I'm constructing are: var myQuery = from tab1 in context.Table1 join tab2 in context.Table2 on Table1.ID equals Table2.Table1ID where tab1.TypeCode == ...

Linq: convert an list<int> to a string of ints?

I have an int array with the value 3,99,6. How do i convert the array into the string 3,99,6 with linq? ...

ASP Repeater with Linq to entities object - child list problem

Hi I have a Linq CodeBehind Function Like this var result = from m in context.Products.Include(n=>n.Categories) where m.IsActive == true select m; The m is Product Class which holds the list of categories. On the ASPX page in repeater I want to have acces to first category where my product is. I trie...

extract generic list from generic list using linq

Hi, I have a generic list of type 'a' which contains a generic list of type 'b', something like this: List<A> lA = new List<A>(); List<B> lB = new List<B>(); lb.Add(new B()); lb.Add(new B()); lb.Add(new B()); lA.Add(lB); What I want to do is build a new list of type 'b' from lA where a property on 'b' is true. Any help with this wou...

Implement a LINQ Expression parameter

I am using an interface I found, which has a method that takes a LINQ expression as a parameter. How would I implement this method to use the LINQ Expression? I can see it being very useful, but dont how to write the code to use it!! Its a repository interface. signature is... IQueryable<T> Get(Expression<Func<T, bool>> criteria); ...

how to fetch values from special attribute names with LINQ and XML

XML is like this: <element customer-name="blabla" customer-identifier="blabla2"> and I'm using VB.net, doing something like this: name = xmlstring.<element>.@customer-name This doesnt work, because you cannot enter "@customer-name" in the LINQ query. Is there way to escape minus sign becoming an operator? ...

LINQ where query on collection of different derived classes

I have a collection of different objects that derive from the same parent. How can I extract objects of a particular type from a collection containing mixed types e.g. public class A {} public class B : A {} public class C : A {} The collection will contain objects of type B and C I'm halfway there just need help filling in the '[]...

Expression and Parameter

I have this method: public static Expression<Func<MyEntity, bool>> MyMethod(string someId) { return o => o.SomeProperty.Equals(someId); } This is being passed to another method that uses entity framework with this expression to retrieve the matching items. My problem is it doesn't work. If I replace the someId as part ...

Linq Grouping - aggregate, outside of a group by

hello, i've got a SQL query, that works as follows: SELECT TOP 100 Max(Table_ID) as Max_ID, Col1, Col2, Col3, COUNT(*) AS Occurences FROM myTable GROUP BY Col1, Col2, Col3 ORDER BY Occurences DESC How can I write an identical Linq query? The issue is, that as soon as i apply my grouping, I cannot access the non-grouped columns...

Accessing Rows In A LINQ Result Without A Foreach Loop?

For every single LINQ query I've written, I've always used a foreach loop to go through the result. Now, I have a program where I want to get the first 50 rows of the result, do some calculations with those rows, then get the next 50 rows of the result etc. What is the good standards way to do this using LINQ and C#? ...

Filter parent/child table (one to many association) in linq query based on entities in child table?

I have a table (Projects) which is linked to projectVersions on projectID projectVersions contains several columns on which I'd like to filter a returned project (and associated projectVersions) list. For example there is a "capacity" column and a "country" column. I am doing a filtered list of projects on one page and I'd like to inc...

Translate LINQ Inline query to extension method

I can't seem to figure out the LINQ Join extension method... I have the following LINQ inline query: var cc = from z in zipcodes join c in contactsRepo.UDF_SelectSome() on z.Zipcode equals c.Zip What is the equivalent of this in LINQ-extension-method syntax? ...

How to get the max row number from a table by using linq

SELECT ISNULL(MAX(ColumnName) + 1, 1) AS ColumnName FROM TableName How to write this query in LINQ.Is there any way to convert sql to linq . i want a converter. Above query works well but i want the same output on linq .How to ? I know how to select max var products = ((from p in db.TableName select p...

Removing nodes from XDocument

This removes all elements from the document: XDocument document = XDocument.Load(inputFile); foreach (XElement element in document.Elements()) { element.Remove(); } document.Save(outputFile); This doesn't have any effect: XDocument document = XDocument.Load(inputFile); ...

Using SQL Will Fix Concurrency Issues?

I am developing a set of applications that all hit the same database, and concurrency has been one of the biggest issues I've had to deal with. I'm developing solutions to work around these issues, and I recently thought of using SQL queries instead of LINQ queries to update databases. Because SQL has pessimistic concurrency control, ...

LINQ And Concurrency Question

I am developing three applications that all share a common database. I'm running into many different concurrency issues and was wondering if it is possible to prevent any other queries to execute when certain queries are running (in other words, locking the database so there won't be any concurrency issues). Edit: I'm using LINQ to SQ...

Resubmitting Changes ?

If I want to resubmit changes, do I have to redefine them after making my first submit, or can I simply call the SubmitChanges() method again as in the following code: DB.SubmitChanges(); Thread.Sleep(1000); DB.SubmitChanges(); Edit: The reason why I want to do this is because I have two different linq queries that handle conflicts ...

How can i do this with Extensions methods or Linq ?

Hello It is a little hard to explain it with my poor english but i will try. In below list sequence, if a item first field has same value with another item first field value but not same second fields. As result i want to collect items which has same first field but not second fields. It looks quite easy but i think it is not any.Cons...