linq-to-sql

Linq equivalent to SQL LIKE [a-f]

SELECT * FROM Customer WHERE Name 'LIKE [a-f]%' How Can I acheive this in Linq?? In other words in linq how can i select all Names between a and f?? Thanks, ...

LINQ to SQL context.GetChanges

Hi Experts, I have two tables in a LINQ to SQL dbml file. I am trying to get all the changes submitted to context, which I can get by using var myOtherContext; var changes = context.GetChangeSet(); foreach (var change in changes) { Type t = change.GetType(); if (change is Product ) { myOtherContext.GetTable...

SQL query generated by LINQ TO SQL statement

How would i know the SQL statement generated by my Linq to sql query? ...

Does ADO.NET Entity Framework have a construct similar to Linq-To-SQL's GetTable<T>

I'm trying to do something similar in Entity Framework, that I'm very used to doing in Linq-To-Sql. Now my question is if EF has the same capability, that I'm unable to figure out. Linq-To-Sql: dataContext.GetTable<T>(); Would yield a Queryable collection of type 'T'. In Entity Framework I would like to do the same: //NOTICE: T...

Retrieve two values in the same linq query

I'm starting with linqToSql and I still have some problems making my queries. For example, I want to retrieve in the same query two values, a subset of elements, and an integer with the count of the elements. This is how I did it separately: int totalElements; IEnumerable<ClsTax> result; result = (from t in db.tax sel...

In LinqToSql, is it possible to have a custom Insert method that Auto-Syncs the primary key?

I can do this if I leave the Entity's Insert method as 'Use Runtime' and have it deal with the inserts directly, but I need to use an SP. I have tried to simply return the @@Identity from sql server and then assign this to the ID but this causes a change notification and LinqToSql thinks it has changed, even though it's just the ID. ...

Linq to SQL Cache Dependency

Hi, I'd love to hear people's views on the pros and cons of mixing SQL Cache Dependency with Linq to SQL, as described in this article: http://code.msdn.microsoft.com/linqtosqlcache This works for me, but I'm interested to know if anyone has any alternatives? Cheers, Tim ...

What could be causing db.SubmitChanges() to not work in linq-to-sql?

I've set up a very simple example with LINQ-TO-SQL in WPF. I can get an object (pageItem) out like this and I can change the property and when I call SubmitChanges() it gives me no error but it doesn't save the change. MainDataContext db = new MainDataContext(); var pageItem = (from p in db.PageItems where p.Id == 1 ...

Linq help - Sql trace returns result, but datacontext returning null

var adminCov = db.SearchAgg_AdminCovs.SingleOrDefault(l => l.AdminCovGuid == covSourceGuid); adminCov keeps coming back null. When I run SQL profiler, I can see the generated linq, when I past that into management Studio, I get the result I expect. LinqToSql generates this: exec sp_executesql N'SELECT [t0].[AdminCovGuid], [t0].[Admin...

Multiple Left Outer Joins in LinqToSql?

Is it possible to accomplish something like this using linqtosql? select * from table t1 left outer join table2 t2 on t2.foreignKeyID=t1.id left outer join table3 t3 on t3.foreignKeyID=t1.id I can make it work using both DataLoad options or join syntax. But the problem is whenever I add a second left join, linqtosql queries with MULT...

Can I data cache an IQueryable<> collection?

can this be cached? ...

Linq to Sql - Populate JOIN result into a List

I am not sure if this can be done, but here's the scenario. I want to turn this sql into linq: SELECT * FROM Department d INNER JOIN Employee e ON e.DepartmentID = d.DepartmentID Department - Employee is 1 to many relationship. I have created a custom object that I would like to populate the result into. public class DepartmentSum...

Can Entity Framework deal with multiple result sets (each from joined tables) from a stored procedure?

In Linq to SQL, I can't find an easy way to deal with multiple result sets returned by a stored procedure where each result set is from table joins. Each result set does not map directly to a table. (can't change this behavior). For now, it seems using a DataSet is a lot simpler. Can the current Entity Framework or the upcoming one, 4.0...

How to instruct linq to sql to update table columns to their default values on UpdateOnSubmit/SubmitChanges?

I have a Linq to SQL entity which emit the following two sql statements: UPDATE [identity].[AddressTypes] SET [Name] = @p4 WHERE ([SurrogateKey] = @p0) AND ([Name] = @p1) AND ([LastUpdatedOn] = @p2) AND ([LastUpdatedBy] = @p3) -- @p0: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [b0cf44d9-c6ba-de11-b194-001e37f334ea] -- @p1: I...

Linq to Sql - DataContext design issues and considerations in ASP.NET MVC application

I am using "Single data context per atomic operation" approach while using Linq to Sql in an ASP.NET MVC application. So far, I have been using a singleton datacontext, which I learnt has many issues, so I refactored the code to use single datacontext per atomic operation. An example of a controller action is now as follows (refactorin...

Detaching a Query in Linq to Sql

For my application I want to be able (if possible) to execute a LINQ to SQL query outside of it's context. The reason this would be nice for me is that I would store the IQueryable in objects in the cache. When I later need them they would be executed and the cached object would be updated with the items from the query. The reason I wa...

How to do Select All(*) in linq to sql

Hi How do you select all rows when doing linq to sql? Select * From TableA In both query syntax and method syntax please. Thanks ...

How to work with multiple updates by linq to sql?

Hi everyone! First of all, I would like to ask if it is possible to do a multiple records editing by linqtosql method in one click event? What I've been trying to do is to edit all the names in the table which are having the same account number. I was able to edit but only one name has been edited and the rest are not,if it is possible,...

LINQ to SQL - selecting a list of the highest version numbers...

I am trying to write some Linq to SQL that will bring me back a list of rows containing a single instance of BaseQuestionIDs but I want the row with the highest version, so, from the following table of data: Id CreatedDate Version BaseQuestionID 2 2009-10-07 13:47:27.687 1 2 3 2009-10-07 13:49:35.010 ...

MVC ActionMethod not finding passed in Value

Hi, I have a Create ActionMethod, something along the lines of: [AcceptVerbs(HttpVerbs.Post)] public ActionMethod Create(Journey journey) { if (Request.IsAjaxRequest()) { //Save values return Json(new { JourneyID = journey.JourneyID } ); } } The Journey object that I pass in is from my LINQ2SQL datamodel. I call the ab...