linq-to-sql

Does LINQ to SQL support POCO?

If I want to work with an object and leverage LINQ to SQL what (if anything) do I need to add to my entity classes to ensure my application can talk to the data store? (keep out any discussion of repository patterns here as I'm just looking for what is required inside my business objects) ...

How to persist Strategy Pattern (behavoir) with LINQ 2 SQL?

I am designing an app that will be using LINQ2SQL to persist the data in a database. I often use the Strategy pattern. For instance, I may have a ClubMember object which can use different cost strategies like the following: class ClubMember { public String name { get; set; } public String email { get; set; } private IMembe...

SQL Express 2008 Not committing LINQ to SQL writes in sequence?

Hi, I've an event-driven app that has recently started using SQL Express 2008 (instead of Std version) in dev and test to store the current state of a state machine. After moving to SQL Express, we started seeing a discrepancy between the order in which we write to the database (using LINQ to SQL) and the order in which SQL Express Prof...

How to intercept and modify SQL query in Linq to SQL

Hi, I was wondering if there is any way to intercept and modify the sql generated from linq to Sql before the query is sent off? Basically, we have a record security layer, that given a query like 'select * from records' it will modify the query to be something like 'select * from records WHERE [somesecurityfilter]' I am trying to fi...

Linq to SQL: Projections, ViewModels, non translatable queries

My application has to deal with large amounts of data, usual select size is about 10000 rows. In order to improve performance it is recommended only to select the data needed. When i have to do calculations or any meaningful business i am comfortable with selecting all the data in order to instantiate my model correctly so i can rely on...

Linq - pulling a value from a null query result

I have a linq query that needs to pull a date column out of a row. The expression currently looks like this myObject.OrderByDescending(s=> s.MyDate).Where(s => s.CRAStatus.Description == "CheckedOut").FirstOrDefault().MyDate) The problem is that if there are no rows that are "CheckedOut", the query will return a null and attempting to...

Should I use a Struct instead of a lightweight data class for my Linq2Sql data?

I often take the classes that linq2sql generates and create a simple data-only class like so public class myentity { public Guid id { get; set; } public string name { get; set; } // etc } I don't put methods in these classes and I mainly use them as helper classes so I can serialize to/from json and other similar action...

Select all NOT in requirement, Linq to SQL

I have a simple set of tables... List - Id Items - Id Entries - EntryId - ListId - ItemId I'm trying to design a Linq query that will take a given ListId and return all of the Items that do not have an Entry with that ListId on it. It sounds pretty simple, but it keeps coming up wrong. Any ideas? ...

C# Generics Question

I have a couple of areas in an application I am building where it looks like I may have to violate the living daylights out of the DRY (Don't Repeat Yourself) principle. I'd really like to stay dry and not get hosed and wondered if someone might be able to offer me a poncho. For background, I am using C#/.NET 3.51 SP1, Sql Server 2008, a...

Convert SQL Server signed int to Binary(4)

I messed up. I wanted to store IP addresses compactly in SQL Server and chose 'int' for the column type. 'int' are 32 bit signed integers while IPs really are 32 bit binarys. My question is: How do I convert my existing signed int into Binary(4) in SQL Server and how should I properly parse the string-IP representation from .Net 'Reques...

LINQ to SQL value BETWEEN two double values

I'm using LINQ to SQL to query my database, I have a query very similar to this: var result = from db.MyTable.Where(d => (double)d.Price >= minValue) I need the where clause to have a d.Proce >= minValue, and d.Price =< maxValue (like a T-SQL BETWEEN clause). How can I do this? ...

ASP.Net MVC requirements vs ASP.Net? (hosting question, plus LINQ-to-SQL question)

Hi everyone, I'm jumping into ASP.Net MVC and wanted to know how tough it's been for hosting providers to support it. One thing that I'd like to know is how I can port my local MVC app to a hosted provider if I'm using LINQ to SQL. I assume I have to move the dbml files over in some way? What else that's special in contrast to a regu...

Passing LINQ Results to a function

I have a class called UserInfo that contains details about a given user. There are several places in code where the data might be queried and I'd like to have a single function to fill the UserInfo object with the corresponding data from the Linq Query. var userData = dc.Users.Where(λ => (λ.Login == username) && λ.Activ...

How to do "INSERT INTO table1 (...) SELECT (...) FROM table2" in LINQ?

How do I write a LINQ to SQL equivalent of: INSERT INTO Table1 (field1, field2, field3) SELECT field1, field2, field3 FROM Table2 WHERE (field1= @field1) Thanks ...

LINQ Dynamic WHERE but Clean Special Chars first

Hi Guys I have the code below but it give me an error at .Where(p => Regex.Replace(p.Phone, rgPattern, "") == Regex.Replace(phone.Trim(), rgPattern, "") string rgPattern = @"[\\\/:\*\?""<>|()-]"; var members = from m in Context.Members select m; if (!String.IsNullOrEmpty(phone)) members = members.Where(p => Regex.Replace(p.Phon...

Is it possible to override a linq to sql property?

I have a date time property in a linq to sql model and I want to override this in a partial class. I tried changing the inheritance modifier and then overiding in the partial class, but it didn't work. Is this sort of thing possible? I'm developing in 3.5 framework and its and ASP.NET MVC application. My override is: public override...

Add an error to the model from my linq to sql partial class in ASP.NEt MVC

I am doing some validation in the OnChanging event of Linq-to-sql model partila class and want to fire an error into my model. is this possible? event code > partial void OnCommissionStartChanging(System.DateTime value) > { > if (this.CommissionStart > this.CommissionEnd) > { > //add error to model or t...

How to Debug "Linq to SQL" Source

In accordance with the steps from MSDN, I can debug .net framework source code,But I can not debug step in Linq to SQL code,anyone help me! Thanks. ...

LINQ: Create persistable Associations in Code, Without Foreign Key

Hello, I know that I can create LINQ Associations without a Foreign Key. The problem is, I've been doing this by adding the [Association] attribute in the DBML file (same as through the designer), which will get erased again after I refresh my database (and reload the entire table structure). I know that there is the MyData.cs file (as ...

How to find number of rows affected in LINQ to SQL?

Does anybody know how to find the number of rows affected AFTER I have submitted changes to the data context in LINQ to SQL? At first I was doing something like this: Using db as New MyDataContext() db.Users.Attach(modifiedUser, True) db.SubmitChanges() Dim rowsUpdated As Integer = db.GetChangeSet().Updates.Count End Using...