linq

Problematic behavior of Linq Union?!

Hi, consider the following example: public IEnumerable<String> Test () { IEnumerable<String> lexicalStrings = new List<String> { "test", "t" }; IEnumerable<String> allLexicals = new List<String> { "test", "Test", "T", "t" }; IEnumerable<String> lexicals = new List<String> (); foreach (String s i...

linq2twitter error - This property cannot be set after writing has started

I'm trying to search using twitterContext.Search then straight after I'm calling CreateFriendship() and i'm getting the error 'This property cannot be set after writing has started' I think this is a http error, but I'm not sure how to go about flushing the first request before i do the 2nd one. ...

Conditional Join In LINQ?

I am trying to write a query that grabs information from one database and joins it to information in a different database. TableA idA valueA idB TableB idB valueB The tricky part is that in TableA, idB isn't always defined, so when I do a normal join, I only get results where TableA has a idB value. What I want is to be able to gr...

'Timeout Expired' error when buffer cache clean

I am going to sum up my problem first and then offer massive details and what I have already tried. Summary: I have an internal winform app that uses Linq 2 Sql to connect to a local SQL Express database. Each user has there own DB and the DB stay in sync through Merge Replication with a Central DB. All DB's are SQL 2005(sp2or3). We...

Deserialize JSON Objects in Asp.Net MVC Controller

Hey guys I'm trying to deserialize an object which was generated by LinqToSql. The user is allowed to edit the data of the object in the view and then it gets posted back to the controller. The edited Data comes in JSON. How does this action have to look like? Something like... public ActionResult(JsonObject json) { MyClass c = Js...

How can I find all items beginning with a or â?

I have a list of items that are grouped by their first letter. By clicking a letter the user gets alle entries that begin with that letter. This does not work for french. If I choose the letter a, items with â are not returned. What is a good way to return items no matter if they have an accent or not? <% char alphaS...

Linq to xml, retrieving generic interface-based list

I have an XML document that looks like this <Elements> <Element> <DisplayName /> <Type /> </Element> </Elements> I have an interface, interface IElement { string DisplayName {get;} } and a couple of derived classes: public class AElement: IElement public class BElement: IElement What I want to ...

Use of where in multiple joins to remove rows - linq

hi, I have a table of orders. the status is on the soilorders which is joined to the orders. I only want to return orders where the joined soilorder does not have status "Removed". I had thought that join sso in db.SoilSamplingOrders on ord.order_id equals sso.order_id where sso.status.Equals("Removed")!=true but then no re...

is it possible to write data to a collection in wpf?

Hello. In looking through samples I have seen a number of examples where it is possible to present data within a wpf applicaiton by binding to collections. However I was wondering is it possible to write to a collection from an applicaiton. Say for example i have 2 or more fields such as names and I wanted to have hte ability to add up t...

Update Entity through a new Object in LINQ to SQL

Hey Guys I'd like to update an entity via linq, but since I edit the entity in a view after serializing it, I don't have direct access to the entity inside the data context. I could do it like this: entity.property1 = obj.property1; entity.property2 = obj.property2; ... thats not cool... not cool at all. Next thing I tried is to do ...

Combining Variable Numbers of Lists w/ LINQ

I have a list (List) of objects. Each of those objects contains a list (List) of strings describing them. I'm needing to create a dropdown containing all of the distinct strings used to describe the objects (Cards). To do this, I need a list of distinct strings used. Any idea how/if this can be done with LINQ? ...

Turn Function or Stored Procedure Result into "live" Result for LINQ

Is it possible to turn result sets obtained in LINQ through a stored procedure or function call into a "live" set of objects of which I can retrieve Foreign Key related objects? If, for example, my stored procedure returns a set of rows (= LINQ objects) of type "Contact", then I can't seem to obtain Contact.BillingAddress (which is rela...

LinQ optimization

Here is a peace of code: void MyFunc(List<MyObj> objects) { MyFunc1(objects); foreach( MyObj obj in objects.Where(obj1=>obj1.Good)) { // Do Action With Good Object } } void MyFunc1(List<MyObj> objects) { int iGoodCount = objects.Where(obj1=>obj1.Good).Count(); BeHappy(iGoodCount); // do other stuff with 'objects' co...

Determine if point intersects 35km radius around another point? Possible in Linq?

Assume I have a point at the following location: Latitude: 47°36′N Longitude: 122°19′W Around the above point, I draw a 35Km radius. I have another point now or several and I want to see if they fall within the 35Km radius? How can I do this? Is it possible with Linq given the coordinates (lat, long) of both points? ...

List to Columns in LINQ

Given an IEnumerable<T> and row count, I would like to convert it to an IEnumerable<IEnumerable<T>> like so: Input: Row Count: 3 List: [1,2,3,4,5,6,7] Output [ [1,4,7] [2,5] [3,6] ] EDIT I would like this to work for any IEnumerable and not depend on T being an Int32. How can I do this using LINQ? ...

Linq: read node innertext

i have a xml document like this: <ns:a xmlns:ns="http://NS1"&gt; <ns:b> <c xmlns="http://differentNS"&gt; c_text </c> <x xmlns="http://differentNS"&gt; Wanted </x> <d xmlns="http://differentNS"&gt; d_text </d> </ns:b> </ns:a> Now i want to use linq to read the element's "x" inner text. ...

Using a method vs. a property to retrieve data from a class using LINQ

I'm building a content-managed site with a homegrown API built by several developers I work with. The API is just a nice LINQ-like ORM-like layer between the Sitecore CMS (our CMS in this case) and our C# code to bind data items to controls. I've found in several places I've had the opportunity to to decide between creating methods and p...

Linq: convert string to int array

I have a function (tointarray) to convert a string into an array of ints, but I am not very satisfied with it. it does the job but there must be a more elegant way to do this, perhaps Linq could help here. unfortunately I am not very good in Linq. do you guys know a better way? my function: { string s1 = "1;2;3;4;5;6;7;8;9;10;11;12"...

NHibernate: QueryOver<> help

Hi, I'm just starting out with NHibernate and I'm having trouble with running more complex queries. I have entities with a list of tags attached. The user will provide two lists of tags, include and exclude. I need to find all the entities that have all of the include tags, and exclude any entites that have any tag in the exclude lis...

How to Update with LINQ?

currently, I'm doing an update similar to as follows, because I can't see a better way of doing it. I've tried suggestions that I've read in blogs but none work, such as http://msdn.microsoft.com/en-us/library/bb425822.aspx and http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx Maybe these do work and I'm m...