linq-to-sql

DataContext compiled query problem with .NET 4

My project (UI layer is asp.mvc) was developed using .NET 3.5. After upgrading to .NET 4.0 I have got problem with compiled queries: [ArgumentException: Query was compiled for a different mapping source than the one associated with the specified DataContext.] System.Data.Linq.CompiledQuery.ExecuteQuery(DataContext context, Object[] ...

Linq2sql count grouping vote entity query problems, can't get properties once grouped?

I'm building a music voting application, similar to stack overflow almost. I have 3 tables, Charts, ChartItems, Votes. I'm trying to bring back a list of chartitems, which link to a single chart, with the number of votes for each chart item counted. This is what I am trying currently var firstList = from chartItem in db.ChartItems ...

Linq-to-SQL: Use a shared transaction between LinqDataSource and DataContext?

Hello all, I have a page where I use two ASP DetailsView controls to render data from two different, but related, LinqDataSource objects. My primary table is represented in the first DetailsView/LinqDataSource set, and I use the LinqDataSource's built-in update functionality to persist changes when the DetailsView is in edit mode. The p...

How to write a query that calculates a value using a previous records value?

I'm trying to figure out the best way to calculate a value that is based on the previous records values. I'm sure it's possible, I just can't figure it out. Consider a table that has StartTime & EndTime. Along with these values is are 2 different types of wages: OnDuty & OffDuty. OnDuty = All time between StartTime and EndTime. ...

Unity with a Linq to Sql DataContext. RegisterType or RegisterInstance

Here's the basic setup. On an ASP.Net website, there are a few pages that display reports from data that comes from a database. All the data comes via stored procedures that is accessed usign Linq to Sql. These pages may have some very high traffic at different times. We're using ASP.Net with the MVP pattern, and Unity for IoC (although ...

Turkish character problem in select query - SQL Server

SELECT [ID] ,[Name] ,[Markup] ,[Status] FROM [dbxyz].[dbo].[Block] WHERE Name = 'Hakkımızda' Linq2Sql sends this query to SQL Server 2005 but because of the character problem (ı) it does not get the right dataset as a response. No rows returns. I can not change the collation of database because it is a hosted service and I have ...

How to pass Title for a view that uses a Linq Collection

I'm learning Linq and MVC2 I'm making progress, but I'm a little stuck on how I should get a page descrption into a View that uses a collection. In my controller I have the following construct public ActionResult Group(int id) { var result = (from d in db.ErrorDetails.Where(r => r.ErrorTerminal.ErrorTerminalGroupID == id) ...

LINQ + TransactionScope will not change isolation level in SQL Server Profiler

Hi Guys, I'm using the following format for commiting changes to my db using linq. Begin Transaction (Scope Serialized, Required) Check Business Rule 1...N MyDataContext.SubmitChanges() Save Changes Done In Previous Query To Log File End Transaction Scope But in the SQL Server profiler I see the following line in the Conne...

Update with value from a select query in Linq To SQL

Update TableToBeUpdated Set ColumnNameId = (Select MasterColumnId from MasterTable where Id = @Id) Where ForeingKeyId = @Id AND AnotherColumn = @AnotherColumn How to achieve the above with one select statement and an update statement with a subquery? Currently what I'm thinking is. //First Select statement ...

Dynamic Linq: Get the current data context

I'm using the Dynamic Linq features described in: http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx which works fine as long as I'm only refering objects where foreign keys are setup properly. Is there any way to referense a Table where foreign keys aren't setup? i.e. so...

How to use LINQ to SQL after changes in database

Note: I know there was disscussion about similar questions before, like in: link text but i have to know how to handle this scenario: Problem: I wrote program that use LINQ to SQL and it will be send to client. Tables that my program uses may be changed ( let's say only added new columns). Is there any way to not update, recompile a...

How to do a LIKE query with linq?

How can i perform an LIKE query within Linq? I have the following query i would like to execute. var results = from c in db.costumers where c.FullName LIKE "%"+FirstName+"%,"+LastName select c; ...

Convert linq model to generic list

hi, I have an existing class Image which is used extensively throughout my application. I need to return a generic list of images (List) to the frontend but as there is no stored proc in the 3ed party DB I am quering I need to use Linq to Sql. I have create a dbtm file of the database I am quering in my DAL which looks like: ImageCat ...

SQL DateTime Overflow when using DateTime.Now + LINQ to SQL

Im getting a strange error when trying to add a new item to a table using LINQ error : SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. Code: dbc.TblEvent newEvent = new dbc.TblEvent(); newEvent.Subject = "Registered"; newEvent.PersonID = PersonId; newEvent.EventDate = Date...

Make sql where clause prioritize one prefix-like-search above another

I have an sql table with some nvarchar columns, lets call them 'Title' and 'Value'. I currently use a linqtosql query to make a prefix search to find rows in this table, like so var result = from _item in GetTable() where _item.Title.StartsWith( "hello" ) || _item.Value.StartsWith( "hello" ) select _item; return result.Take( 10...

Can Linq-to-SQL Do an Insert or update as needed?

I have a distributed app that sends data via WCF to a server to be stored in the database (SQL Server 2008). Usually this data is new. So I just do InsertAllOnSubmit(). But occasionally, due to communication oddities with the handheld devices that run the client side I get an object that is already in the server. Is there a way to sa...

Getting error while updating LINQDatasource

When I try to update Linqdatsource binded to gridview get following error "Could not find a row that matches the given keys in the original values stored in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous Select operation." Note :- I have specified DataKeyNames ...

linq datetimeoffset comparison with today

I have a class with a DateTimeOffset property: public class Sample { public DateTimeOffset expires { get; set; } } and eventually a collection of them: IEnumerable<Sample> collection; 2 questions: What is the best way to create a method that returns all the Sample items from the collection where expires is greater than n...

LINQ: Expression.Call(typeof(Queryable), "Select"...

I'm attempting to create a small "automapper-esq" utility that will take a LinqToSql entity and map it to a "projection class". So far I have something like this: class Entity { public int ID { get; set; } public string WantedProperty { get; set; } public string UnWantedPropertyData { get; set; } ...More Unwanted Proper...

Mapping database int to enum flags in model

My application has a model which currently uses an integer in the SQL database to store the value of a [Flags]Enum. The Enum looks something like this: namespace MyProject.Models { [Flags] public enum MyEnum : int { FirstThing = 1, SomethingElse = 2, YetAnotherOne = 4 } } So if a particular row...