linq-to-sql

Implementing filters for a SQL table display on a view in ASP.NET MVC (C#) and LINQ-to-SQL?

A follow-up from this question, I've changed my controller and routing around so that now the sort value is assigned by ?sort= however I also want to implement the ability for users to filter the table based on a select set of values: Technician : Tech1, Tech2, Tech3, etc. Category : Category1, Category2, Category3, etc. Priority : Prio...

Can I set "Parameters per stored procedure" higher than 2100 in SQL Server 2005/08?

There is a hard limit of the number of parameters any single SQL statement can have, and that is 2100 (for SQL Server 2005), or 1024 (for SQL Server 2000). Does anyone know of a way to increase that number? If you'd like to know "why" (as I would be dying of curiosity myself), the ansewr is in this: MyL2SDataContext.Accounts.Where(acc...

Struggling with DDD, Repository Pattern, and Associated Domain Models...

I'm really struggling to wrap my head around some of this stuff. Let me give an example of where I'm struggling. I'm using Linq-2-Sql as the DAL for my app and the IRepository pattern used in the MVC Storefront sample app from Rob Conery. In my domain I have a Customer Model which has a collection of Address Models. In my UI there is a...

Can LINQ-To-SQL be used Asynchronously?

Can LINQ-To-SQL be used Asynchronously? Are there any OR Mappers that allow Asynchronous operations? CLOSED: See http://stackoverflow.com/questions/252355/how-to-write-asynchronous-linq-query ...

How do I get Linq to SQL to recognize the result set of a dynamic Stored Procedure?

I'm using Linq-to-SQL with a SQL Server backend (of course) as an ORM for a project. I need to get the result set from a stored procedure that returns from a dynamically-created table. Here's what the proc looks like: CREATE procedure [RetailAdmin].[TitleSearch] ( @isbn varchar(50), @author varchar(50), @title varchar(50)) as declare ...

Building Dynamic LINQ Queries based on Combobox Value

I have a combo box in Silverlight. It has a collection of values built out of the properties of one of my LINQ-to-SQL objects (ie Name, Address, Age, etc...). I would like to filter my results based off the value selected in a combo box. Example: Say I want everyone with a last name "Smith". I'd select 'Last Name' from the drop down ...

How to write a expression for a linq to sql property?

My appologies upfront for the lengthy question. I made quite an effort to make my question as clear as possible in one go. Please bear with me. ;o) any help will be greatly appreciated! I have the classes Branch and Text: class Branch int ID Text WebDescription and a bunch of other properties class Text int ID string UK string N...

LinqToSQL - no supported translation to SQL

Hi, I have been puzzling over a problem this morning with LinqToSQL. I'll try and summarise with the abbreviated example below to explain my point. I have DB two tables: table Parent { ParentId } table Child { ChildId ParentId [FK] Name Age } These have LinqToSQL equivalent classes in my project, however, I have writ...

LINQ to SQL - Update to increment a non-primary-key field - thread-safe

I have two tables (well, two relevant for this question) : Bets (holds the bets; Columns : Id, , MessagesPosted, ) Bets_Messages (holds the bets' forum messages; Columns : Id, BetId, ) When I insert a new BetMessage in Bets_Messages I want to update (increment to be precise) the corresponding field in Bets. In pure T-SQL that would be...

How to delay loading aproperty with linq to sql external mapping?

I have a table that contains some blob fields that I don't want to load by default. In a dbml file it is possible to set the delay loaded property for such fields. Is there a similar option for external mapping files? ...

Using Linq to get a single column rowset from a stored procedure, How can I clean up this hack job?

I've got a guy who is a wizard at writing stored procs and he can munch 10 tables down to a single column in no time at all. I'm half tempted to invest a couple of days to work with him on returning XML instead of rowsets because I can digest those all day long without any problem. I say that because it is a challenge to get a result of ...

LINQ InsertOnSubmit: NullReferenceException

I have this code: using DC = MV6DataContext; using MV6; // Business Logic Layer // ... public DC.MV6DataContext dc = new DC.MV6DataContext(ConnectionString); IP ip = new IP(Request.UserHostAddress); dc.IPs.InsertOnSubmit(ip); dc.SubmitChanges(); // in Business Logic layer: public class IP : DC.IP { public IP(string address) { ... } ...

Linq to Sql Enums and Conditional Operator

Whichever way I do it, it seems something goes wrong when using the conditional operator on enum values in Linq to Sql. For example var ret = from listings in db.Listings select new Listing { ID = listings.ID, //etc OrderStatus = listings.OrderItems.Count > 0 ? listings.OrderItems.First().Order.OrderStatus : OrderStatu...

SQL Server 2005: Nullable Foreign Key Constraint

I have a foreign key constraint between tables Sessions and Users. Specifically, Sessions.UID = Users.ID. Sometimes, I want Sessions.UID to be null. Can this be allowed? Any time I try to do this, I get an FK Constraint Violation. Specifically, I'm inserting a row into Sessions via LINQ. I set the Session.User = null; and I get this err...

Search in LINQ to SQL

Hi, I have some code like this: Function GetTypeFromTableName(ByVal _TableName As String, ByVal _DataContext As DataContext) Dim Mytype As Type = (From t In _DataContext.Mapping.GetTables Where t.TableName = "dbo." + _TableName Select t.RowType.Type).SingleOrDefault Return Mytype End Function Dim DBA As New LINQDataContext _...

How to call a UDF in a linq to sql query?

How would the following sql statement translate to a linq query? select ID, Price, dbo.fGetText(DescriptionID, defaultLanguage, currentUserLanguage) from Products The UDF fGetText is quite substantial and used throughout the code base, so it needs to be encapsulated (as a UDF or otherwise, perhaps a Linq Expression). ...

Do you put Linq2SQL queries all over the place or in dedicated DAL classes?

I have always inserted my Linq2SQL queries all over the place, in almost every class all over the place. I woud like to know what your strategy about where to put your Linq2SQL queries? Do you put them in separate datalayer classes or do you store them where they are used all over the place? I think that I need to chang my strategy f...

Linq to SQL: add a custom column and the Order By it?

How could I do something like this in Linq to SQL (VB.NET if possible)? SELECT *, ISNULL(DueDate, DATEADD(year, 10, GETDATE())) AS DueDateForSorting FROM Tasks ORDER BY DueDateForSorting ...

LINQ to SQL: Self-referencing entity - ParentID/ChildID association

I have a Task entity in my Linq to SQL dbml. It's self referencing with ID and ParentID columns. I have an Association that associates the two IDs together. it seems like everything works fine in the intellisense. It'll let me type out Task.Parent.ID and even Task.Parent.Parent.ID, etc. However, it gives me the ol' "Object referen...

Converting "is null" into a linq to sql statement

I am having trouble replicating the following sql as a LINQ statement select TableA.* from TableA left outer join TableAinTableB on TableA.Id = TableAId where TableBId is null The following returns no lines from TableA in db.TableA join AinB in db.TableAinTableB on TableA.Id equals TableAId where AinB.TableBId == null select TableA ...