linq

Combining two expressions (Expression<Func<T, bool>>)

I have two expressions of type Expression<Func<T, bool>> and I want to take to OR, AND or NOT of these and get a new expression of the same type Expression<Func<T, bool>> expr1; Expression<Func<T, bool>> expr2; ... //how to do this (the code below will obviously not work) Expression<Func<T, bool>> andExpression = expr AND expr2 ...

Keep HTML tags in XML using LINQ to XML

Hi, I have an xml file from which I am extracting html using LINQ to XML. This is a sample of the file: <?xml version="1.0" encoding="utf-8" ?> <tips> <tip id="0"> This is the first tip. </tip> <tip id="1"> Use <b>Windows Live Writer</b> or <b>Microsoft Word 2007</b> to create and publish content. </tip> <tip id="2"> Enter a <b...

Edit composite key value using LINQ

I have a table which uses three columns as a composite key. One of these column values is used as a sequence tracker for ordered related records. When I insert a new record I have to increment the sequence numbers for the related records that come after the new record. I can do this directly in SQL Server Management Studio, but when I ...

C#, Winforms & LINQ to SQL.. Datacontext lifecycle?

We use an enterprise framework that we wrote to facilitate all sorts of company specific stuff that we do. Within the framework, we provide a LINQ to SQL ORM to use when appropriate. All of this is based on the Microsoft MVC framework. On the MVC side, we new up a datacontext in our base controller. This allows us a full datacontext lif...

SQL CLR Objects for Heavy Operations

Here is my scenario: I have implemented set logic in my C# framework. Sets can contain a large quantity of objects, perhaps even up to 1 million in the worse case. Assume sets just contain lists of objects called Doc. Because of the potential large number of objects, I would like to give the developer a choice of how to create and us...

LINQ to XML, ORM or someting "Completely Different"?

I'm working on a Silverlight Project with all the features and limitations that entails. This is an update to a previous product. The intent, in order to be quick to market, is to maintain as much of the back-end (webservices, database, etc..) as at all possible. Our mandate it to only touch the back-end if there is no other way. We'...

What is the best way to learn new technologies?

I wonder what would be the best way to learn "new" technologies (i.e. like LINQ, WPF, WCF, AJAX, latest C# 3.0 stuff, etc)? How do you learn the best? Is it by books, webcasts, online articles, tutorials, examples or hands-on-labs? Also, how do you make sure that you will remember the learned stuff? (reading a book/article again? dig...

How do I get the index of the highest value in an array using LINQ?

I have an array of doubles and I want the index of the highest value. These are the solutions that I've come up with so far but I think that there must be a more elegant solution. Ideas? double[] score = new double[] { 12.2, 13.3, 5, 17.2, 2.2, 4.5 }; int topScoreIndex = score.Select((item, indx) => new {Item = item, Index = indx}).Orde...

Convert List<List<T>> into List<T> in C#

I have a List<List<int>>. I would like to convert it into a List<int> where each int is unique. I was wondering if anyone had an elegant solution to this using LINQ. I would like to be able to use the Union method but it creates a new List<> everytime. So I'd like to avoid doing something like this: List<int> allInts = new List<int>...

How can I query an xml file and save the result in another xml file.

Hello, I am new with learning the possibilities of Linq to XML and I recently have found that I can query an xml like a data base (I am quite fascinated by it now). My question is How can I query an xml file and save the result in another xml file?: string url = "employees.xml"; XElement employees= XElement.Load(url); if (emplo...

Deleting rows in a DataGridView

I am currently using a DataGridView coupled with a subform to implement a master/detail setup. The DataGridView only supports row selection and deletion events - editing/adding items is entirely handled in the subform. As such, I maintain a list of entities that I make changes to, while binding the DataGridView to a list of anonymous ty...

Extract results from List<Customers> using LINQ

I have a List of Customers List<Customers> cust = new List<Customers>(); cust.Add(new Customers(){ID=1, Name="Sam", PurchaseDate=DateTime.Parse("01/12/2008")}); cust.Add(new Customers(){ID=2, Name="Lolly" PurchaseDate=DateTime.Parse("03/18/2008")}); I want to show 2 seperate results like: Purchases by Customer in Yr // Grouping by...

What OR/M tool that supports Linq/Iqueryable would you recommend?

I asked this question reguarding the use of Linq-2-Sql with the Rob Conery's use of the Repository in his MVC Storefront app and got an excellent response from Matt Briggs: L2S is used to generate the DAL, but the only thing that should know about the DAL is the repository, so a translation is made to his domain objects. ...

Is there a way to convert an IEnumerable into a collection of XElements?

I'm trying to persist an XML file to disk using LINQ. I have a class of business objects including collections of strings (List) that I want to convert into XML. Is there a simple, one liner to convert this list into a list of XML Elements? For example, my list may be: List<string> collection = new List<string>() {"1", "2", "3"} The ...

Select items by tag when searching multiple tags

Hi, I'm struggling a bit here so I thought why not ask: Every entity in my system has a list of tags (a list of strings), and I want to be able to search for multiple tags at once. I have a IQueryable to work with. Every Entity has a IList called Tags and my input parameter is a IList. I simply could go through all tags and do IQuerya...

What are the differences and pros and cons of these ORM tools/technologies?

Duplicate: http://stackoverflow.com/questions/66156/whose-data-access-layer-do-you-use-for-net http://stackoverflow.com/questions/380620/what-object-mapper-solution-would-you-recommend-for-net-closed http://stackoverflow.com/questions/217655/using-entity-framework-entities-as-business-objects http://stackoverflow.com/questions/146087/...

Transforming a one to many sql query into a List of nested classes

What is the best way of taking a query and transforming it into a nested class list without doing a subselect for each row? eg. 1 aaaa 1 bbbb 1 cccc 2 dddd 3 eeee into 1 aaaa bbbb cccc 2 dddd 3 eeee ...

Generate an XSD using LinqToXml

Does anyone know how to generate an XSD using LinqToXml? I can't find any examples of this anywhere. The XSD will be of the following fairly low level of complexity: <?xml version="1.0" encoding="utf-8" ?> <!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)--&gt; <xs:schema ele...

Best way to remove multiple items matching a predicate from a c# Dictionary ?

I need to remove multiple items from a Dictionary. A simple way to do that is as follows : List<string> keystoremove= new List<string>(); foreach (KeyValuePair<string,object> k in MyCollection) if (k.Value.Member==foo) keystoremove.Add(k.Key); foreach (string s in keystoremove) MyCollection.Remove(s); The re...

LINQ to SQL not recognizing new associations?

I have two projects using legacy databases with no associations between the tables. In one, if I create associations in the DBML file, I can reference the associations in LINQ like this: From c In context.Cities Where c.city_name = "Portland" _ Select c.State.state_name (assuming I added the link from City.state_abbr to State.state_ab...