linq

Variable 'x' is declared but never used error

Ok, so I have this nifty bit of code from Microsoft, and I have a little hiccup that I want to get rid of. The original code prints out the ChangeConflictException x on the console, but I erased this line. Now, every time I use this bit of code, I get the error: "Variable 'x' is declared but never used". What is the most efficient wa...

Linq and DBNull - Getting error

Hi All, I'm getting an error when selecting from a rows.AsEnumerable(). I am using the following code... var rows = ds.Tables[0].AsEnumerable(); trafficData = rows.Select(row => new tdDataDC { CalculationCount = row.Field<Int64>("biCalculationCountSeqID") , Zone =...

LINQ reflection with Host Level Trust

Hi, I'm having difficulty with my project and deploying it on my web hosting provider. I'm on a shared hosting environment with "Host Level" trust. I have used LINQ in my project but now they've just told me that Reflection is disabled on their shared services. I believe that reflection is required to be able to use variables within th...

Adding an element to an array

I m reading data from a source as array. a[n] I need to add one more element to the array. Once i get the array, i create a new array with capacity n+1 and copy all the elements to the new array and put the new element as the last element of the array. I can do this. Is there a better way to do this? especially with Linq? ...

How to delete an item from a Dictonary using LINQ in C#

I need to delete a specific item from a dictonary.. The dictonary is like dict["Key1"]="Value1" dict["Key2"]="Value2" dict["Key3"]="Value3" dict["Key4"]="Value2" How to delete the item if another item has the same value using LINQ Thanks in advance ...

Database for Windows Phone 7

I'm looking to release a really simple application for windows Phone 7. Unfortunately, My Apps need to store some data in the device. say a Database. My colleague found one SQLite library - http://sviluppomobile.blogspot.com/2010/03/sqlite-for-wp-7-series-proof-of-concept.html But How about Linq to SQL or EF for Windows Phone 7. Any L...

Are there any cases where LINQ's .Where() will be faster than O(N)?

Hi all.. Think the title describes my thoughts pretty well :) I've seen a lot of people lately that swear to LINQ, and while I also believe it's awesome, I also think you shouldn't be confused about the fact that on most (all?) IEnumerable types, it's performance is not that great. Am I wrong in thinking this? Especially queries where ...

Calling stored proc with LINQ .ExecuteQuery to return non-mapped fields

I have a stored procedure which returns all the fields of a table plus one, ie: tablename.*,count(suchandsuch) Of course, when executing this via LINQs ExecuteQuery I can get back instances of the table's class in an IEnumerable<>, but I also want the extra field which the stored proc tacks on. Is this possible? My current code look...

Linq chain queries execution order

I'm experiencing some performance issues using linq, that led me to my first stackoverflow question: The test function in the following code, is executed a differente number of times for these two linqs queries: int[] mydata = { 1, 2, 34, 5, 67, 8 }; var query = from i in mydata select new { i,v=test(i)}; var query2 = query.Wh...

How to choose that which ORM would be feasible for or Application? e.g if we are using Linq then why not hibernate

How to choose that which ORM would be feasible for a web Application? e.g if we are using Linq then why not nhibernate? and Which one is better and why ...

Need Linq Query Help

I have the following simple Linq query: (from container in Container join containerType in ContainerType on container.ContainerType equals containerType where containerType.ContainerTypeID == 2 select container).Max (row => row.SerialNumber) As is, this query works fine. The problem is that SerialNumber, in the DB, is an nvarchar type...

Linq expression. Help mimize code

Please, help minimize the following code: There is a class with dictionary property: class Foo { public int Field { get; set; } public Dictionary<int, bool> dic { get; set; } } And a list of Foo instances. I want to get united dictionary from all class instances like that: ... var items = new List<Foo> { new Fo...

How to return Anonymous Type while using Linq

Do any one know how to return an anonymous type. I am using Linq where i need to return the following code private <What's the return type to be provided here> SampleLinq(Int32 Num) { var query = (from dept in obj.DeptTable where dept.Id == Num select new { dept.DeptName, dept.DeptId }); return (query) }...

How to add data to a dictonary from xml file in c# using XML to LINQ

The xml file is having the following structure <Root> <Child value="A"/> <Child value="B"/> <Child value="C"/> <Child value="D"/> <Child value="E"/> </Root> and the dictonary Dictionary<int, string> dict = new Dictionary<int, string>(); i need to read the attribute value of "value" from the file and add t...

Adding where clause to nested Linq selects

I'm still new to Linq so if you see something I really shouldn't be doing, please feel free to suggest a change. I am working on a new system to allow officers to sign up for overtime. Part of the data is displayed on a map with search criteria filtering unwanted positions. In order to make the data easier to work with, it is read int...

Merging xml documents using linq to xml and xdocument

I have the following xml: <DOCUMENT> <ARTICLE> <META name="bbb" value="7086" score="0.58" key="6007"/> <META name="ccc" value="7089" score="0.58" key="6008"/> <META name="ddd" value="7087" score="0.58" key="6009"/> </ARTICLE> </DOCUMENT> I need to use linq to xml and an xdocument to allow users in an asp.net page to edit ...

Using Linq with 2D array, Select not found

I want to use Linq to query a 2D array but visual studio c# 2010 express gives the message: Could not find an implementation of the query pattern for source type 'SimpleGame.ILandscape[,]'. 'Select' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? var doors = from landscape in this.ma...

Linq Query Help - Detecting Null Values

I have the following Linq query: (from container in Container join containerType in ContainerType on container.ContainerType equals containerType where containerType.ContainerTypeID == someIDValue select container).Max (row => Convert.ToInt64(row.SerialNumber)) This query works great as long as at least one Container row meets the cri...

Different Forms Of LinQ

string grid = @"08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08"; string[] res = grid.Split(' '); var lowNums = from n in res where n.Length > 0 select int.Parse(n); I am having trouble converting the above linQ statement to a lambda WHERE equivalent. The following works, but only returns am en...

Linq To Xml datasource for grid view is not working. The grid show no rows

Hi All, I'm getting some Xml back from a service. I would like it to be the datasource of a grid view on my aspx page. Here is a sample of the Xml <?xml version="1.0" encoding="utf-16" ?> <ArrayOfTripTollCompleteDC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <TripTollC...