linq

LINQ - Add property to results

Is there a way to add a property to the objects of a Linq query result other than the following? var query = from x in db.Courses select new { x.OldProperty1, x.OldProperty2, x.OldProperty3, NewProperty = true ...

WPF and LINQ to Entities binding to newly added records

I'm in the process of learning LINQ to Entities and WPF so forgive me if I get some terminology wrong. I have a model which contains Clients and I want the user to be able to bulk enter up to 20 clients at a time (this will be done by data entry staff off a paper list so I want to avoid entering one and saving one). I was planning on a...

Using the All operator

I would like to see an example that makes the best use of the ALL operator when using a parent child reltaionship in LINQ. Can you show me one please? ...

Replacing foreach with LINQ query

I have the following code in one of my methods: foreach (var s in vars) { foreach (var type in statusList) { if (type.Id == s) { Add(new NameValuePair(type.Id, type.Text)); break; } } } This seems sort of ineffective to me, and I was wondering if there was a way to substitute...

How to set property value of type 'System.Xml.Linq.XElement' to TextBox.Text?

Hi, I have Linq object which has one field of type 'System.Xml.Linq.XElement'. When bound to Gridview this XML is properly displayed as text. However, when I try to edit that row and update Linq object I get error: Cannot convert value of parameter 'CustomData' from 'System.String' to 'System.Xml.Linq.XElement'. What is the easiest way...

Retrieve description and category of node with LINQ

I have the following tags <NodeA desc="Household"> <NodeA desc="Cheap"> <NodeA desc="Cheap Item 1" category="Cooking" /> <NodeA desc="Cheap Item 2" category="Gardening" /> </NodeA> </NodeA> <NodeA> ...and so on With the help of a helpful guy here, I got to retrieve list of category using this: .Where(attr...

select two attributes in a node using LINQ

I have the following node: <NodeA desc="Cheap Item 1" category="Cooking" /> I selected the 'category' attribute using the following: .Where(attr => attr.Name == "category") .Select(attr => attr.Value); How can I select both the 'desc' and 'category' now ...

Object reference not set to an instance of object error

I get this error "Object reference not set to an instance of object error" when I execute this piece of code xe.Element("Product") // Select the Product desc="household" element .Elements() .Select(element => new { Name=(string) element.Attribute("desc"), Count=element.Elements().Count() }); What could b...

What are the advantages of LINQ to SQL?

I've just started using LINQ to SQL on a mid-sized project, and would like to increase my understanding of what advantages L2S offers. One disadvantage I see is that it adds another layer of code, and my understanding is that it has slower performance than using stored procedures and ADO.Net. It also seems that debugging could be a cha...

.where on a LazyList not working

I am using Rob's implementation of LazyList and it is working great. However, I am not able to get a .where clause working on a child entity of the type LazyList. For eg. something like var qry = orderRepository.GetOrders(); qry = from p in qry where p.Items.Where(t => t.Name == "test") select p; produces the following compile time...

LINQ to SQL: Stored Procedure Results

How can I change the class name of stored procedure result generated by LINQ to SQL designer (besides messing with designer.cs)? Also, how can you perform a linq query on the result set of the stored procedure? ...

LINQ to SQL - Updating Data Context Objects in Partial Classes

I have created an extensibility method for deleting one of my Linq To Sql objects called Reservation. Well, in this partial method I created, I want to update some other objects. I can't seem to get the update to be persisted in the database. Here is my partial method for deleting the reservation. public partial class LawEnforcementDat...

VB XML query on attributes using LINQ

I'm trying to learn LINQ and have a question on querying XML using VB. My XML: <Procedure-Text> <A ID="marker1"></A>Do This Procedure </Procedure-Text> <Procedure-Text> <A ID="marker2"></A>Do That Procedure </Procedure-Text> How can I specify my query to get only the procedure text that has the ID attribute marker2? In ot...

Best way to update a LINQ model coming from a form

I'm designing forms in my ASP.NET MVC application that will receive objects. Here's what a typical edit action looks like: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, Person person) { peopleService.SavePerson(person); return Redirect("~/People/Index"); } The SavePerson call in the ser...

Why is my database not being updated with this LINQ query?

Code: Public Sub UpdateDB() Dim db As New linqclassesDataContext Dim article = From p In db.articles _ Where p.id = articlelist.SelectedValue _ Select p article.FirstOrDefault.body = FCKeditor1.Value Try db.SubmitChanges() Catch ex As ChangeConflictException fcke_output.Text = ex.Message End Try End Sub no e...

How to specify .NET Anonymous object return type in Linq using Func<T,Q>?

How do you specify the Func signature for anonymous objects? new Func<DataSet, **IEnumerable<int>>** I am having a trouble with return type where I have specified as IEnumerable<> in the Func declaration Error I am getting from the expression is Cannot convert expression type 'System.Collections.Generic.IEnumerable<{ParentNodeId...

LINQ multiple where clause

Hi, I have a course table which I need to search based on keywords typed in the search box. Here is a sample query: SELECT * FROM Courses WHERE Title LIKE '%word%' OR Title LIKE '%excel%' OR Contents LIKE '%word%' OR Contents LIKE '%excel%' How can I convert this in LINQ where LINQ would dynamically generate WHERE statements based...

Strange Linq Error

I am using Linq to convert an array of any object to a CSV list: String.Join(",", (From item In objectArray Select item.ToString()).ToArray()) This is giving me the strange error: "Range variable name cannot match the name of a member of the 'Object' class." I can get round it by wrapping the string in a VB StrConv method, with a set...

What's the smart way to implement OrderBy / ThenBy?

I'm implementing a LINQ clone in Lua, but that's not too relevant here, and I've got most features done (enumerable/queryable, not the precompiler yet), but can't think of a smart way to implement OrderBy's ThenBy. Currently I sort once, then place in new lists and then sort those sub lists and finally merge the results again, but that...

Is Linq2XSD Dead?

Does anyone have any updates on this since the alpha 0.2? ...