linq

Is it bad to "think" in LINQ when the skill isn't transferrable outside C#?

I use LINQ in my code all the time. I've gotten to the point where it just seems so natural to Group, Order, an organize a bunch of objects using the LINQ syntax that I struggle to think how I would do the same things without it. I had never delved into the SQL-esque world before this, but I imagine many people who learned even the nor...

LINQ to Entities: Using DateTime.AddMonth in Lambda Expression

Hello, I've been reading some posts but I don't find a solution to a problem that I have with LINQ To Entities, Lambda Expressions and DateTime.AddMonth. The problem is that I'm trying to use DateTime.AddMonth inside a Lambda Expression and I'm getting this error: "LINQ to Entities does not recognize the method 'System.DateTime AddMo...

linq to sql ExecuteQuery() as IQueryable

ExecuteQuery() method returns an IEnumerable but is there a way to make it return IQueryable? ...

Browse to a file directory and display its files in a listview

Hello fellow coders. Would anyone offer tips, links, code snippets on how to browse to a file folder from within an ASP.NET 3.5 web application and list the folder contents within a ListView? Regards, Rey R. [neophyte web application developer] ...

XML to LINQ in VB, noob question

I'm basically brand new to LINQ. I've looked around a lot on here and am pretty confused. I've seen some examples that allow me to strong type objects using LINQ but I don't really understand them because they're in C#, which I guess lets you do different things with LINQ(I think?). Anyways, this is what I'm trying to do: Dim productXM...

Linq query

Hi, I'm a big noob with Linq and trying to learn, but I'm hitting a blocking point here. I have a structure of type: Dictionary<MyType, List<MyObj>> And I would like to query with Linq that structure to extract all the MyObj instances that appear in more than one list within the dictionary. What would such a query look like? Th...

Linq Not Retrieving Correct Items in a Big Table

I'm with a very strange problem. I've a table with more than 800.000 records and 2GB mdf Database. When I try to get the last records: I'm only getting the records until one month ago, the last ones doesn't show up. Dim Items = From Item In DB.Items _ Where Item.CatID = CatID _ Order By Item.PubDate Descending ...

LINQ to SQL entity column name attribute ignored with guid primary key

I was working with a simple entity class with LINQ to SQL (SQL Server 2005 SP3 x64). [Table( Name="TBL_REGISTRATION" )] public sealed class Registration : IDataErrorInfo { [Column( Name = "TBL_REGISTRATION_PK", IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert )] public Guid RegistrationID { get; private s...

Whats the Best Practice for a Search SQL Query?

I have a SQL 2008 Express database, which have following tables: CREATE TABLE Videos (VideoID bigint not null, Title varchar(100) NULL, Description varchar(MAX) NULL, isActive bit NULL ) CREATE TABLE Tags (TagID bigint not null, Tag varchar(100) NULL ) CREATE TABLE VideoTags (VideoID bigint not null, ...

Sorting & Unique Records in Linq

I have a datatable like public DataTable functiongettable() { DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Rows.Add("Name1"); dt.Rows.Add("Name5"); dt.Rows.Add("Name6"); dt.Rows.Add("Name3"); dt.Rows.Add("Name3"); dt.Rows.Add("Name6"); dt.Rows.Add("N...

How can I add OrderBy to this LINQ statement?

I'm getting data out of an XML file by sending a where clause as delegate to a custom method: foreach (PageItem pageItem in GetPageItems(xmlDoc, sf => (int)sf.Element("id") == id)) { _collection.Add(pageItem); } which works fine but now I want to add an OrderBy clause as well, but can't get the right syntax, here it doesn't recogn...

How can I make a LINQ query with subqueries in the from statement?

Can I make this type of SQL query on LINQ to SQL? (this query is only a example) select * from orders as o left outer join (select * from ordersdetail where status = 'A') as od on o.id = od.orderid What I need is how can I put a subquery inside de "from" statement. Thanks ...

Using Lambda with Dictionaries

Hello, I am trying to use LINQ to retrieve some data from a dictionary. var testDict = new Dictionary<int, string>(); testDict.Add(1, "Apple"); testDict.Add(2, "Cherry"); var q1 = from obj in testDict.Values.Where(p => p == "Apple"); var q2 = from obj in testDict.Where(p => p.Value == "Apple"); The above lines, q...

Repeaters and DataItems

I am trying to bind a Linq to Sql object to a Repeater object and then update my DataSource. My question is, can binding persist, or do you have to use the CommandArgument to retrieve the record and FindControl to get the updated values everytime? If the former is the case, will someone please provide an example? ...

Best Practice to renumber items in a list? SQL or C#/VB.NET

I have a database table that has a SortOrder integer column. In the UI for adding and editing table items, I have a drop down list of Integer to let the user select where in the sortorder they would like this item to appear. My question is, say the list, {1,2,3,4,5,"last"}, if the user picks a a number, I want that to be the items SortOr...

How to return anonymous type from c# method that uses LINQ to SQL

Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to SQL query, which returns the data as an anonymous type (containing about 6 columns of data of various datatypes). I would like to make this returned object available to other parts of the program, either by returning it to the method-caller, or by...

Searching if value exists in a list of objects using Linq

Say I have a class Customer which has a property FirstName. Then I have a List. Can LINQ be used to find if the list has a customer with Firstname = 'John' in a single statement.. how? ...

LINQ | How do I get SUM without grouping?

Crazy question...however, I want the sum of all the rows in a table for a column (without using the group by clause) Example: Table = Survey Columns = Answer1, Answer2, Answer3 1 1 1 4 3 5 3 3 2 I want the sums for each column. Final results should look like: Ans...

How to retrieve data with LINQ to SQL into a weakly-typed object that can be moved around

In classic ASP we had the record set object. With ADO.Net we had the datatable. Both were simple .Net objects that could be moved around easily. What is the equivalent for using LINQ To SQL? Most examples show "var" being used, however, this seems completely non-oo as you can't move a var around (without a cast hack). My understandi...

IEqualityComparer for anonymous type

I have this var n = ItemList.Select(s => new { s.Vchr, s.Id, s.Ctr, s.Vendor, s.Description, s.Invoice }).ToList(); n.AddRange(OtherList.Select(s => new { s.Vchr, s.Id, s.Ctr, s.Vendor, s.Description, s.Invoice }).ToList();); I would like to do this if it where allowed n = n.Distinct((x, y) => x.Vchr == y.Vchr)).ToList(); I tried...