linq-to-sql

LINQ to SQL deployment problem

Hi all I have an asp.net application developed. It uses LINQ to SQL to access database, using the .dbml designer in Visual Studio 2008. We are installing the application on client, and they have decided to change the database name on their servers. Now, the application does not work because LINQ can't find the database information. This...

LINQ to SQL without VS 2008

In response to one of my previous questions, I was encouraged to check out LINQ to SQL. I like what I see, but I'm struggling to get going with it. I wrote the necessary classes for each database table, but I'm not sure where I'm supposed to put the code. I've been searching the Internet for tutorials, but they all seem to be assuming th...

How to use a custom configuration class for web.config with Linq dbml classes

I have a web project that uses a custom configuration class to store app settings in web.config. I do this to be able to store and access configuration settings in web.config that are based on server name. That way when the project moves from development, to staging, to production, I don't have to remember to change the web.config s...

linq to sql Insert not working on deployed server(IIS)

title speaks for itself, db.ExecuteCommand("INSERT INTO tCSVFile(fileName, fileContent, mimetype, timeCreated) VALUES({0}, {1}, {2}, {3})", filename, EncodeTo64(CreateCSVFile(header, rows)), "text/csv", DateTime.Now ); this works fine from the virtual server but on iis inserting causes nothing to happen. Also tried this.. tCSVFile...

LINQ to SQL Where Clause Optional Criteria

I am working with a LINQ to SQL query and have run into an issue where I have 4 optional fields to filter the data result on. By optional, I mean has the choice to enter a value or not. Specifically, a few text boxes that could have a value or have an empty string and a few drop down lists that could have had a value selected or maybe ...

Linq returning list of anonymous types

Caan somone advise the best approach to what i'm trying to acheive (linq to sql, returning list of data to show in a grid/list etc etc)... Its complaining about anonymous type conversion, and from what i'm reading, thats not elegant way of doing it. Public Function GetHistory(ByVal historyId As Integer) As List(Of ?????????) Using...

Obtaining a table by the item type in LINQ to SQL

How can you make something like this generic return from items in _db.Table select items; I would like to do something like this public class Data<T> ( where T is the model object ) so the Table will change to the value of T How would this look as a generic class with a save method for instance Thanks ...

Linq2sql/GridView: Pagination not working?

What's the best method to bind a linq2sql collection to a GridView, given that I want ot use builtin pagination and sorting? I've tried: public static void BindEnquiryList(EnquiryQuery query, GridView view) { DataContext db = DataContextManager.Context //view.DataSource = (from e in EnquiryMethods.BuildQ...

How to remove and then add child items in LINQ to SQL

I have a serie of child items of a table, that I wan't to delete and then add the new ones. I don't care about performance, because it is a non frequent operation. How must I do it? I have tried Order.items.clear() and Order.Items.Remove(x) but both give me exceptions Simplified code: Dim db As New MainDataDataContext dim o as...

jQuery AlphaNumericPlugin - Copy Paste Issue

I am using the .alphanumeric plugin for jQuery which is certainly doing what I would expect as users type directly into the textbox. But, if a user were to copy and paste a value into the text box, all bets are off. $("#<%= txtNumber.ClientID %>").alphanumeric({allow:"-"}); I can certainly do this: $(document).ready(function() { ...

Problem with discriminators in Linq to SQL

I'm trying to use a discriminator field in my linq to sql setup. I have a base class called Inventory_Item which I have setup to be abstract and then many different services that inherit from it (e.g. BaseWash). Now the properties for the BaseWash association are Base Class Discriminator Value = 1 Derived Class Discriminator Value = ...

How to get the TSQL Query from LINQ DataContext.SubmitChanges()

I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing. There is an error inserting the identity field, and I'd like to see the query it's using to insert this identity field. I don't see the query itself within the quickwatch; where can I find it from within the debugger? ...

Linq to SQL: Why am I getting IDENTITY_INSERT errors?

I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing. There is an error inserting the identity field: Cannot insert explicit value for identity column in table 'Rigs' when IDENTITY_INSERT is set to OFF. The only identity field is "ID", which has a value of 0. It's defined in the DBML as: [Column(Storage=...

How would you write an Upsert for LINQ to SQL?

So I'd like to write a generic Upsert function for LINQ to SQL and I'm having some trouble conceptualizing how to do it. I'd like it to work something like this: var db = new DataContext(); db.Customers.UpsertOnSubmit(customer); So it would have to be generic in some way and I guess and extension method on Table. I've been able to g...

System.InvalidOperationException: Transaction does not match connection. linq to sql

Any one ever seen this? It comes from a .net remoting endpoint hosted in IIS with a 16 process web garden. So there are many concurrent transactions in each thread pool per process. We are using linq to sql and the Transaction object that is from the DataContext, NOT the transactionScope object. It seems to happen either around the dispo...

Business logic in contructor - C# / Linq to Sql

I'm extending (not sure if it's the right word here) a partial Cart class that got generated in Linq to SQL database model. The business logic is that there can be only one Cart per customer. If a customer doesn't have a cart, it should be created; if a customer has a cart, it should be returned. Here's what I'm doing: public partial...

What's the most efficient way to do these two foreach-loops?

Hi folks, i'm not sure this is the best way to do the following code. I'm not sold on a foreach inside another foreach. Could this be done *better** with Linq? *I understand that better could be either a) more performant b) easier to read / more elegant c) all of the above NOTE: .NET 3.5 solutions accepted :) NOTE2: the two IList's ...

Duplicate LINQ to SQL entity / record?

Hi guys, What would be considered the best practice in duplicating [cloning] a LINQ to SQL entity resulting in a new record in the database? The context is that I wish to make a duplicate function for records in a grid of an admin. website and after trying a few things and the obvious, read data, alter ID=0, change name, submitChanges(...

Linq 2 SQL - Generic where clause

Hi all Is there a way to do this public T GetItemById(int id) { Table<T> table = _db.GetTable<T>(); table.Where(t => t.Id == id); } Note that i.Id does not exist in the context as linq does not know what object it is working with, and Id is the primary key of the table ...

Adding related records in LINQ

Hi there, Processing an XML file with LINQ to add records into a table in a SQL Server database via a data context. As we are adding records we need to assign the parents in various other tables. Most of the time we can find the existing parent and use it but sometimes we will need to create a new parent. Thought we could do this like...