linq

Is there a difference betweeen Select * and Select [list each col]

I'm using MS SQL Server 2005. Is there a difference, to the SQL engine, between SELECT * FROM MyTable; and SELECT ColA, ColB, ColC FROM MyTable; When ColA, ColB, and ColC represent every column in the table? If they are the same, is there a reason why you should use the 2nd one anyway? I have a project that's heavy on LINQ, and I...

Assignment in .NET 3.5 expression trees

Is it possible to encode an assignment into an expression tree? ...

Cross apply in Linq

Is it possible to use SQL Server 2008 CROSS APPLY with LINQ-2-SQL? Example SQL: select d.dateCol, tvf.descr, tvf.value from dateTable d cross apply tvFunction(d.dt, 'anotherParam') tvf where d.category='someCat' CROSS APPLY enables using values from a table (dateTable in the example) as parameters to a tablevalue function. This is v...

switch statement in linq

My code for sql connection using linq is: var query1 = from u in dc.Usage_Computers where u.DomainUser == s3 select u; // selects all feilds from table GridView1.DataSource = query1; GridView1.DataBind(); I have a field called "Operation" in the table "Domainuser" which has values like "1, 2, 3". When I populate t...

In LINQ how to find a distinct item that is joining 2 tables?

Given the Below Tables. How do I get the Distinct name given the other ID of 76 in LINQ? **Table S** SID OtherID ------------------------------ 1 77 2 76 **Table Q** QID SID HighLevelNAme LoweLevelName --------------------------------------- 10 1 Name1 Engine 11 1 Name1 ...

Insert a row of grid into datacontext.

Looking for an example in linq about how to insert a row of a gridview into datacontext. ...

ListView with LINQ Datasource insert template

It seems like this should be straightforward but I'm boggling. I've got my listview all setup and bound to my LINQ datasource. The source is dependent on a dropdown list which decides which branch information to show in the listview. My edit template works fine but my insert template won't work because it wants the branch ID which I w...

sort columns of gridview in asp.net c#

Can anyone tell the function to sort the columns of a gridview in c# asp.net. The databound to gridview is from datacontext created using linq. I wanted to click the header of the column to sort the data. Thanks! ...

c# query ms access against sql server

I have been asked to setup a course leaflet system for a college. For whatever reason in the past their current system is not linked to their actual course file, they wish to close this link so course leaflets are related to actual course codes. Unfortunately their course file is a ms access database linked to many of their existing syst...

Filter EntityDataSource on Association value

I really like Entity Framework, but there are some key pieces that are a challenge to me. Can anyone tell me how to filter an EntityDataSource on an Association column? EF hides the FK values and instead has an Association property. Given an Entity, Person, with a PersonType association, I would have expected something like this to work ...

Using XQuery in Linq To SQL?

Let's say I have a table that has a column of XML type data. Within SQL, I can execute the following statement: select top 10 *, Content.value('(/root/item/value)[1]', 'float') as Value from xmltabletest where Content.value('(/root/item/MessageType)[1]', 'int') = 1 The result set contains only the records matching ...

How scalable is LINQ?

Recent conversations with colleagues have produced varying points of view on this matter. What say you, SO members? I know, even the concept of scalability can be taken in so many different ways and contexts, but that was part of the discussion when this came up. Everyone seemed to have a different take on what scalability really means....

How to compare dates in LINQ?

I want to check if a given date is more than a month earlier than today's date using LINQ. What is the syntax for this? Thanks in advance. ...

Which LINQ syntax do you prefer? Fluent or Query Expression

LINQ is one of the greatest improvements to .NET since generics and it saves me tons of time, and lines of code. However, the fluent syntax seems to come much more natural to me than the query expression syntax. Which do you prefer and if you write standards for your company, do you enforce one over the other? ...

How can I combine this code into one or two LINQ queries?

I'm perhaps being a bit lazy asking this here, but I'm just getting started with LINQ and I have a function that I am sure can be turned into two LINQ queries (or one nested query) rather than a LINQ and a couple of foreach statements. Any LINQ gurus care to refactor this one for me as an example? The function itself loops through a lis...

What's the hardest or most misunderstood aspect of LINQ?

Background: Over the next month, I'll be giving three talks about or at least including LINQ in the context of C#. I'd like to know which topics are worth giving a fair amount of attention to, based on what people may find hard to understand, or what they may have a mistaken impression of. I won't be specifically talking about LINQ to SQ...

SQL for the web

Does anyone have experience with a query language for the web? I am looking for project, commercial or not, that does a good job at making a webpage queryable and that even follows links on it to aggregate information from a bunch of pages. I would prefere a sql or linq like syntax. I could of course download a webpage and start doing ...

LINQ, Polymorphism, MetaDataMapping, Inheritance Mapper

Hi, I am writing a small program. The interface I am writing to control each repository that is made defines a method of Save(IPublicObject). I am using LINQ for the SQL Version of the repository CRUD. My question is this. I would like to have only the one method which accepts the interface type. I want to think how I can best loca...

Automatically add some Where clauses to a Linq Expression Tree

I am using the Entity Framework and Linq to Entities. I have created a small database pattern & framework to implement versioning as well as localization. Every entity now consists of two or three tables, (ie Product, ProductBase & ProductLocal). My linq always includes the following boilerplate code: from o in DB.Product from b ...

Using Linq to concatenate strings

What is the most efficient way to write the old-school: StringBuilder sb = new StringBuilder(); if (strings.Count > 0) { foreach (string s in strings) { sb.Append(s + ", "); } sb.Remove(sb.Length - 2, 2); } return sb.ToString(); ...in Linq? ...