linq-to-sql

Best practice for removing Database calls from MVC Controller classes

Hi All, I have an Action method in an ASP.NET MVC Controller class that handles form posts from a fairly basic "create/edit a user" page. I'm new to MVC so I've been following code samples from various Microsoft tutorials, this is how the method looks currently: [AcceptVerbs(HttpVerbs.Post)] public ViewResult Save([Bind(Prefix = "Servi...

How do you implement Pipes and Filters pattern with LinqToSQL/Entity Framework/NHibernate?

While building by DAL Repository, I stumbled upon a concept called Pipes and Filters. I read about it here, here and saw a screencast from here. I am still not sure how to go about implementing this pattern. Theoretically all sounds good , but how do we really implement this in an enterprise scenario? I will appreciate, if you have any ...

Linq to Sql with ADO.Net Data Services

I am considering using ADO.Net Data Services in a project for the purpose of getting data over to a Silverlight client. I'd like to use the Data Services with my existing Linq To Sql classes and designer. I probably could regenerate everything as ADO.Net entity objects, but I feel this would be a bad design for DRY reasons. I'm new to...

Multiple WHERE clause in Linq

I'm new to LINQ and want to know how to execute multiple where clause. This is what I want to achieve: return records by filtering out certain user names. I tried the code below but not working as expected. DataTable tempData = (DataTable)grdUsageRecords.DataSource; var query = from r in tempData.AsEnumerable() where ((r.Fie...

LINQ to SQL - Is it true that SubmitChanges() automatically starts a transaction?

I need to use transactions with LINQ to SQL and I was reading around to get familiar with it. Is it true that SubmitChanges is already transactioned? ...

What options do I have for LINQ projections?

In LINQ, I'd like to project different names than those from the database tables. "Friendly names" that I can use for column headers. Names that have "%" or possibly a " " (space). The query below won't compile. Is something like that possible or am I stuck using the dreaded _ underscore for everything? dim query = from p in ctx.Som...

Compiling Linq to SQL queries from a non-trivial IQueryable

Is there a way to use the CompiledQuery.Compile method to compile the Expression associated with an IQueryable? Currently I have an IQueryable with a very large Expression tree behind it. The IQueryable was built up using several methods which each supply components. For example, two methods may return IQueryables which are then joined i...

Linq to Sql and Non-PK, unique-FK relationship issues

Hello everyone, I've recently been reading Louis Davidson's book on Sql Server Database Design and found it quite informative. I've picked up on alot of concepts that I didn't previously know alot (or anything) about. Primarily - I picked up on a way to set up database relationships that I hand't tried before. Basically you use a surro...

Weird Select/Delete query generation in Linq2SQL

Hi For some or other reason Linq2SQL generates the following on 1 of my tables for a delete: DELETE FROM [dbo].[Tag] WHERE ([TagId] = @p0) AND ([Type] = @p1) -- @p0: Input UniqueIdentifier (Size = 0; Prec = 0; Scale = 0) [fb538481-562d-45f2-bb33-3296cd7d0b28] -- @p1: Input TinyInt (Size = 1; Prec = 0; Sc...

How do I handle submits using objects from different datacontexts?

I've been running into a problem where using objects from two datacontexts that are of same type, won't submit objects on. To make this matter simple consider the following LINQ-to-SQL design where we have database tables describing cars and persons. +--------------+ +--------+ | Car | 1 1 | Person | +--------------...

linq .net with dynamically generated controls

This is a very strange problem and i really dont have a clue whats causing it. What is supposed to happen is that a call to the BLL then DAL returns some data via a linq SPROC call. The retunred IMultipleResults object is processed and all results stored in a hashtable. The hashtable is stored in session and then the UI layer uses thes...

Loop through LINQ field values

I have a text file with placeholders such as: Thank you for your order [OrderNo]. Your order will be shipped to: [Name] [Street1] [Street2] etc The placeholders are the field names in the database surrounded by brackets. I want to retrieve a single record from the database like: var order = (from o in testContext.OrderTables where o...

How to compare Dates in C#

Is there a way to compare 2 DateTime variables in Linq2Sql but to disregard the Time part. The app stores items in the DB and adds a published date. I want to keep the exact time but still be able to pull by the date itself. I want to compare 12/3/89 12:43:34 and 12/3/89 11:22:12 and have it disregard the actual time of day so both of ...

Stop Linq2SQL using Named Pipes?

I have a nice little Linq2SQL project however when deployed the database is on another server. I keep getting a named pipe error that the remote server doesn't exist - yet it does, it has Named Pipes enabled (protocol + surface) SQL 2005. TCP connections work fine. I've tried setting the library in the connection string to a TCP one, I ...

DRY LINQ statements for tables with common columns

Here's an interesting problem. Is there a way to write some code using LINQ to SQL which is capable of performing a table UPDATE knowing only that the table it is given contains columns x, y, z but not knowing at compile time which table it is dealing with? I have several tables in my DB schema which share some columns and I need to app...

Improving performance Linq to Sql Compact Edition

Hi I'm writing a WPF client app, using Linq to Sql with Sql Compact edition. The db is relatively small (3MB) and read-only. Bottom line is that The performance are not as good as I hoped them to be, and I'm looking for tips and practical ways to increase that. More facts: The schema contains around a dozen of entities with extensive r...

C#, Linq2SQL: Building up expressions

How do you do it? I sit here and trying to make things simpler for myself and others. But I can't seem to decide what way would be the best. The issue is this: Start with a collection of something from a data context, and then start filtering out on a whole bunch of different criterias. If this, then those or perhaps those unless that ...

Validating string lengths based on related database columns

At the one end of my web application I have a database table storing a load of pieces of text. In the middle I have an API that separates my application tiers. At the other end I have a user interface consisting of many TextBoxes (or input type=text form elements, if you prefer). I need the maxlength properties of the TextBoxes to be ...

Structure map InstanceScope.Hybrid with asp.net mvc misbehaves

I'm really stuck here. I have a asp.net mvc application and use StructureMap 2.5.3 (SM) to inject service and repository classes in my controllers. All controller are made by a SM factory. I also have a Linq to SQL datacontext which I wanted to cache by hybrid. public class DBRegistry:Registry { public DBRegistry() { ...

Linq expression for surrounding numbers in an array

I need a linq expression that will find the nearest numbers (both "greater or equal" and "less or equal") in an array for a given number. E.g. Array - 1, 33, 66, 100 If I have the number 10, I want to return 1 and 33. If I have the number 70, I want to return 66 and 100. If I have the number 33, I want to return 33 and 66. I could do ...