linq

Enum.ToString() not working in tooltip

Hi, I have a Linq Query where I do the following: query = context.Select(a => new { Course = (CourseType)a.CourseCode, CourseDetail = sting.Format("Course: {0}\r\nCourse Detail: {1}", ((CourseType)a.CourseCode).ToString(), a.CourseDetail) }); enum CourseType{ Unknown = 0, FullTime = 1, PartTime = 2 } a.CourseCode is an int...

Add a user-defined scalar function as a property to a Linq-To-Sql class

I have the follow Linq query ... which executes correctly: from t in Tasks where LookupTaskStarted(t.TaskId) == true select new { t.TaskId, t.Number, Started = LookupTaskStarted(t.TaskId) } Is there anyway to create this as a property on the Linq-To-Sql class? Or do I always have to reference it like this? ...

Operation could destabilize the runtime?

I'm having a little bit of trouble understanding what the problem is here. I have a bit of code that pulls records from a database using LINQ and puts them into an object which is cast into an interface. It looks a bit like this: public IEnumerable<ISomeObject> query() { return from a in dc.SomeTable select new SomeObje...

Editing the LINQ to SQL object model

Im using vs2008 and Im also using the autogenerated object model / entity classes from linq to sql (.dbml). Is it possible / recommended to change the autogenerated .cs file. Eg change the behaviour of Equals (in the partical class Courses)? I do know that Equals should be reflexive, symmetric, transitive, consistent and "Equals(null)=...

Shortest method to convert an array to a string in c#/LINQ

Closed as exact duplicate of this question. I have an array/list of elements. I want to convert it to a string, separated by a custom delimitator. For example: [1,2,3,4,5] => "1,2,3,4,5" What's the shortest/esiest way to do this in c#? I have always done this by cycling the list and checking if the current element is not the last on...

How to save XPathExpression result to separate XML with ancestor structure?

Hi! I'm parsing big XML file with XPathExpression selection for some nodes existing at various depth levels. What is the easiest way to export selected nodes to separate XML file, preserving all direct-ancestors nodes (and their attributes)? C# is preferred. Example source XML : <a> <x> <b> <c/> <z/> </b> <c/> </a> <c/...

Rebinding GridView using LinqDataSource

I have a gridview that is using a LinqDataSource for it's datasource. I've added a FooterTemplate so users can insert new records. The Add Button has a command name that puts the values in a Dictionary list and then calls the LinqDataSource.Insert() method. This works fine. But the gridview never refreshes automatically with the new ...

LINQ to Object Help

I have the following entity structure: public class Party { public Int32 PartyId { get; set; } public List<PartyRelationship> RelationShips { get; set; } } public class PartyRelationship { public Int32 PartyId { get; set; } public Int32 RelatedPartyId { get; set; } } Now if I create a generic list of Party objects, su...

Checking existance before inserting via Linq to SQL

I'd like to know if there's an easier way to batch insert a set of records if they don't already exist in a table. For example I have a Tags table in the database having ID, Name columns - given a list of tag names I want to add only those that are not already present. Here's what I came up with: private static void InsertTags(IEnumerab...

Using LINQ how do I have a grouping by a "calculated field"

I am using LINQ to EF and have the following LINQ query: var results = (from x in ctx.Items group x by x.Year into decades orderby decades.Count() descending select new { Decade = decades.Key, DecadeCount = decades.Count() }); So this kind of gets me to where I want to be, in that I get the...

LINQ - Update null integer data field

I have got a field with data type int? price and allow null, when I set book.price = null; and update, it is not saved and does not throw any exceptions, when I change value # null, it is ok. I want set it null, plz help. ...

Linq-to-Sql SubmitChanges not updating fields ... why?

I posted this question yesterday evening, which has led me to discover a huge problem! I have a decimal column in my database called Units, anytime I set the value of the column to a NON ZERO, and SubmitChanges the column updates with the new value. If I try to set the value of the column to ZERO, the SubmitChanges does not update the ...

Regex Replace to assist Orderby in LINQ

I'm using LINQ to SQL to pull records from a database, sort them by a string field, then perform some other work on them. Unfortunately the Name field that I'm sorting by comes out of the database like this Name ADAPT1 ADAPT10 ADAPT11 ... ADAPT2 ADAPT3 I'd like to sort the Name field in numerical order. Right now I'm using the Regex...

Outer Joins and Linq

So I have the following code: return from a in DBContext.Acts join artist in DBContext.Artists on a.ArtistID equals artist.ID into art from artist in art.DefaultIfEmpty() select new Shared.DO.Act { ID = a.ID, Name = a.Name, Artist = new Shared.DO.Artist ...

How can I use Linq with Dataset.xsd files?

How can I use Linq with Dataset.xsd files? I've looked at Linq-to-Datasets and Linq-to-XSD but they don't really seem to work directly with the Visual Studio DataSet.xsd files. EDIT: I actually found a great link for this: link text but I can't seem to figure out what to do if I want to query on related tables. Dim taFields As N...

Why is an InsertParameter not getting its value, but only on the server?

I have a page which consists of a formview containing several Web User Controls (WUCs.) The WUCs get a value from the parent page using a public property, which is stuffed into a HiddenField. I just finished another WUC to manage yet another aspect of a company. It allows you to insert a new record (this is a different table) tied b...

Adding to the Where clause of an Update in LinQ-to-Entities

Let's say I have a table called Product, with three columns: Id, CustomerId, Name. Id is the primary key. The schema is outside of the control of my group, and we now have a requirement to always provide CustomerId as a parameter for all queries (selects, updates, deletes). It's a long story I'd rather not get into ... it involves trig...

Does LINQ use DataRelations to optimize joins?

I can't find the answer to this anywhere, and before I start pawing through generated code with Reflector I thought it'd be worth asking: Suppose I have the following LINQ query run against DataTables in a DataSet: var list = from pr in parentTable.AsEnumerable() join cr in childTable.AsEnumerable() on cr.Field<int>("ParentID") ...

ascending/descending in LINQ - can one change the order via parameter?

I have a method which is given the parameter "bool sortAscending". Now I want to use LINQ to create sorted list depending on this parameter. I got then this: var ascendingQuery = from data in dataList orderby data.Property ascending select data; var descendingQuery = from data in dataList ...

How to create a dynamic Linq Join extension method

There was a library of dynamic Linq extensions methods released as a sample with VS2008. I'd like to extend it with a Join method. The code below fails with a parameter miss match exception at run time. Can anyone find the problem? public static IQueryable Join(this IQueryable outer, IEnumerable inner, string outerSelector, string in...