linq

Using Linq to Sql, how can I get a particular result from a query?

I want to get the last result returned from this query. How do I do this? Last and LastOrDefault aren't supported by Linq to Sql. var docs = (from d in db.Documents where d.Version > 1 orderby d.DocumentID select new ...

Linq Extension methods vs Linq syntax

I'm trying to get a handle on if there's a good time to use standard linq keywords or linq extension methods with lambda expressions. They seems to do the same thing, just are written differently. Is it purely a matter of style? var query = from p in Products where p.Name.Contains("foo") orderby c.Name select p; // or wi...

Does LINQ to Entities reuse instances of objects?

Using LINQ to Entities sounds like a great way to query against a database and get actual CLR objects that I can modify, data bind against and so forth. But if I perform the same query a second time do I get back references to the same CLR objects or an entirely new set? I do not want multiple queries to generate an ever growing number...

Haven't jumped on the Linq bandwagon, what are your reasons for not using linq?

Hi, I seem to be in the minority, but to be honest I am not comfortable with linq and don't see any benefits in my personal development (not to say there are no benefits, just a personal opinion based on my situation). I build web applications (.net, .net mvc) and I love having part of my data layer in stored procedures. One thing I l...

Is it possible to use/access scalar functions with LINQ to SQL?

We have scalar functions in our database for returning things like "number of tasks for a customer" or "total invoice amount for a customer". We are experimenting and looking to try to do this w/o stored procedures ... normally we would just call this function in our stored procedure and return it as a single value. Is there a way t...

Generically typed expression weirdness

The code below gives an error: Property 'Int32 Key' is not defined for type 'ConsoleApplication1.IKeyed`1[TKey]' when the expression e is created but is fine when func f is created, can anyone explain why and if there is a way to fix it? Module Module1 Sub Main() Dim g = New keyedThingGetter(Of KeyedThing, Integer) ...

C#: ?: Operator in LINQ Query

How do I utilize a ?: operator in the SELECT clause of a LINQ query? If this can't be done, how can I emulate one? The goal is to get a CASE block in my select clause. As you might suspect, I'm getting an error: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or m...

LINQ Distinct operator, ignore case?

Given the following simple example: List<string> list = new List<string>() { "One", "Two", "Three", "three", "Four", "Five" }; CaseInsensitiveComparer ignoreCaseComparer = new CaseInsensitiveComparer(); var distinctList = list.Distinct(ignoreCaseComparer as IEqualityComparer<string>).ToList(); It appears the CaseInsensit...

LINQ to Objects: Query with multiple LIKE conditions (OR or AND) possible?

We have a form that allows a user to filter a list with by typing in a textbox. We need to filter the list based on two fields. The FundName and the CompanyName. When the form loads I put the initial LINQ to SQL results into a list so that for every subsequent action (filter) the database is not hit. This speeds things up significantly (...

Contains<T>() and how to implement it

Say a class Person +Name: string +Contacts: List<Person> I want to be able to check if a person has a contact with a certain name without having to create a dummy Person instance. person.Contacts.Contains<string>("aPersonName"); This should check all persons in the Contacts list if their Name.Equals("aPersonName"); I see that ...

Add my linq query resultset to a dataset, c# asp.net 3.5

My query is: var query1 = from u in dc.Usage_Computers.AsEnumerable where u.DomainUser == s3 orderby u.OperationTime descending select new { u.ProgramVersion, u.OperationTime, u.IPaddress, u.ComputerName, ...

Specifying return rows in LINQ2DataSet

I have a requirement to extract a distinct subset of rows from a DataTable, and thought LINQ2DataSets may be a useful and clean way to do this, however it appears that it is not possible to simply identify return rows from a LINQ2DS query as follows var result = from r in fips.AsEnumerable() select r.Field<string>("FACILITY_PROCESS_SUB_...

Can you combine multiple lists with LINQ?

Say I have two lists: var list1 = new int[] {1, 2, 3}; var list2 = new string[] {"a", "b", "c"}; Is it possible to write a LINQ statement that will generate the following list: var result = new []{ new {i = 1, s = "a"}, new {i = 1, s = "b"}, new {i = 1, s = "c"}, new {i = 2, s = "a"}, new {i = 2, s = "b"}, ne...

Streaming and Linq Blobs

I have an object I am using to store document meta data into a table. The body text of the document can be very large, sometimes > 2GB so I will be storing it into a nvarchar(max) field in SQL 2008. I'll use SQL 2008 later to index that field. I won't be using filestreams because they are very restrictive to the database and prevents ...

linq operators like in

HI, I have 3 tables: Clips, Books and relationships between ClipBook Problem is: i need get book that has bookID=4 with some clips i mean many-to-many in simple text sql it will be something like this: select * from Clips where clipID in (select clipID from ClipBook where bookID=4) Question is: How can i do this with Linq without o...

linq help - newbie

how come this work public IQueryable<Category> getCategories(int postId) { subnusMVCRepository<Categories> categories = new subnusMVCRepository<Categories>(); subnusMVCRepository<Post_Category_Map> postCategoryMap = new subnusMVCRepository<Post_Category_Map>(); var query = from c in categories.GetAll() ...

Parallel LINQ in WebApps?

I just watched the last Channel 9 vid on the upcoming parallel extensions to .NET. How would you use this in a web app? I'm specifically thinking of using the parallel Linq extensions against a SQL db. Would this makes sense to use as a way to speed up your data access layer in a multi-user server app? What are the issues (aside from the...

LINQ to SQL Designer Bug

Every time that I change a value in the designer after saving it, the .designer.cs file will be deleted. Can anyone tell me how can I fix this problem? ...

SQL Server Express / MS Access LINQ Features, Which One to Use?

I have a few ASP.Net database front-end websites where MS Access is the back-end. I am trying to use ASP.Net dynamic data website. Should I change this database to SQL Server Express or something else to make it easier or should this work from with MS Access. ...

Linq-to-SQL How to prevent the use of Delete methods?

By convention our DB only alows the use of stored procedures for INSERT, UPDATE and DELETE. For some tables / types there is no DELETE stored procedure, because it is not allowed to delete rows. (You can only update the status of such a type to "deleted"). e.g. a customer may be marked as deleted but is never really removed from the DB. ...