linq

linq to xml and ViewList problem

Hello everybody, I seems to run into problem, and not sure how to make it work. I am trying to take data from XML by using linq and the code works, however when i try use this linq data as DataSource for the ListView, i am getting an error. How can I make it work ? How do i convert my var variable to proper variable so ListView with th...

Distinct list of objects based on an arbitrary key in LINQ

I have some objects: class Foo { public Guid id; public string description; } var list = new List<Foo>(); list.Add(new Foo() { id = Guid.Empty, description = "empty" }); list.Add(new Foo() { id = Guid.Empty, description = "empty" }); list.Add(new Foo() { id = Guid.NewGuid(), description = "notempty" }); list.Add(new Foo() { id...

Read Anonymous Type from DataItem

I would like to read the value from the e.Item.DataItem into a string but for whatever reason, I can't seem to get it, although I can see it in the watch window ...

LINQ - Inserts not working with "junction" table

I have a "junction" table that stores a user's userID (same userID that is in aspnet_membership table) and an ID for a product. I have added this table to a .dbml file. I am trying to do an insert into the table using LINQ and it's failing. Both fields in the junction table are set as primary keys, however, I do not have the aspnet_me...

ASP.NET - Can you use Dynamic Data without Linq to SQL?

I have an application that creates database tables on the fly. I'd like to create an interface to CRUD this data. But because the tables are created as the application runs, I can’t create the Linq to SQL classes by dragging them onto the designer. However, I do know in my code what the tables I want to edit are. Can anyone tell me if ...

Reading inner list only with LinqToXml

With LinqToXml I would like to read out the album list for a given artist from an xml file like <?xml version="1.0" encoding="utf-8" ?> <artists> <artist name="Beatles"> <albums> <album title="Please Please Me" year="1963"/> <album title="With the Beatles" year="1963"/> ... </albums> </artist> ... I tr...

LINQ SQL query check if a obect field is not null

Hi all, I am trying write a SQL query that filters a gridview by the fields that are entered. There are four fields, title, firstname, surname and Company.Name. The first three are fine as they are never null but the fourth can be null. The following LINQ Query works just fine: var listofclients = from client in allcients ...

have a select and want to also retrieve count of the records

Dim db2 As New NewsDataContext Dim filter As String = "System" Dim Msg = From m In db2.Blog_Messages _ **From c In db2.Blog_Comments _** Join u In db2.users On m.userID Equals u.userid _ Where m.userID.Equals(filter) _ **Where c.MessageID.Equals(myRec) _** Group c By c.MessageID I...

Returning proper type after using OrderBy()

I have a collection class that inherits from List<>. I've set up a function to sort the list by a certain property like so: public PlaylistCollection SortByName(IEnumerable<Playlist> playlists) { return (PlaylistCollection)playlists.OrderBy(p => p.Name); } When I try to use the sorted results in my code like this: artistSource.Pl...

In explicit LINQ-to-SQL (C#) does order matter?

Hi, I know Linq-to-SQL is dead, but anyway, I think this is really basic, I'm just confused about what magic Linq-to-SQL does and doesn't do with regards to the SQL it generates. If I have built up an Expression tree as "myPredicate", and have something like this: (from request in DataContext.RequestsTable select request).Where(myPredi...

Turn very simple Expression<Func<T, bool>> into SQL where clause

I have a number of different data sources that I need to query and have been able to do confine all my queries to very simple expressions with no more than 2 conditions. An example of typical complexity of my lamba Expressions is: b => b.user == "joe" && b.domain == "bloggs.com" On my non-SQL data sources I'm ok as I can convert them ...

Observable LINQ, exists ????

Easy question for those who knows what I'm talking about. I want to query a source, and keep UI updated all the time without doing it by myself. There are a few articles out there which talks a bit about it: http://dotnetaddict.dotnetdevelopersjournal.com/dynamic_linq.htm But my point is, it's there any way to do it, directly from D...

Is this LINQable ?

I have a string which denotes a filter path (eg. "Plant Filters\Equipment\Equipment List") The leaf node is of type Filter and rest are FilterFolders. I need to: Go thru each node (not leaf) and get it's -> Folders Check the next entry in the path and see if it matches a folder from above If it matches, it's the last-1, then it gets ...

Binding Grid to a Linq Datasource from Winforms (.net)

Back in the old days (i.e. last month) I'd bind my winforms grid to a dataset and be off and running. By default the grid contents could be updated. (similar to an Excel spreadsheet) But, if I bind a grid to a Linq datasource (either Linq to SQL or Linq to Entities) my winforms grid is locked into a read-only mode. How can I enable an...

Refactoring method that binds controls to LINQ

I have a function that binds LINQ results to the controls on my form. The below code works but I just can't get over the feeling I should be slapped for the copy/paste aspect. Can someone help me with what i need to do to deodorize this? Thank You! private void BindDataToForm() { // Bind data to form CaseNotesData...

How to use Lambda expression to replace string parameter

Instead of calling: var shows = _repository.ListShows("PublishDate"); to return a collection of objects sorted by the publish date, I would like to use a syntax like this: var shows = _repository.ListShows(s => s.PublishDate); What do I need to write to take advantage of the lambda as an argument? ...

Can't store XmlDocument in table column with data type 'xml'

I'm currently working on a small web application using Visual Studio 2008 Express. I'm attempting to retrieve an XML document from a server using a client library and then save the document into a database column (using Linq). The database column has the data type specified as xml. Unfortunately, I've been unsuccessful during my first fe...

Replace a collection item using Linq

How do I find and replace a property using Linq in this specific scenario below: public interface IPropertyBag { } public class PropertyBag : IPropertyBag { public Property[] Properties { get; set; } public Property this[string name] { get { return Properties.Where((e) => e.Name == name).Single(); } //TODO...

Linq2sql Find Top Subscribers Question

Hello all, It has been a while since I have wrote any code due to military obligations (Afghanistan, Reserves) and I have a question with regard to linq 2 sql (hell, I would do this as a stored proc at this point...I really am rusty). I have a table of feed names, and those feeds have subscribers in another table (foreign key associatio...

Why can't I change elements from a linq IEnumerable in a for loop?

Yesterday I wrote the following c# code (shortened a bit for legibility): var timeObjects = ( from obj in someList where ( obj.StartTime != null ) select new MyObject() { StartTime= obj.StartTime.Value, EndTime = obj.EndTime ...