linq-to-sql

How should I design my datalayer so I could potentially swap out nHibernate with linqToSql?

So I'm going with nHibernate, but want to design my datalayer so I could potentially swap out (or switch) to a linqToSql layer. How should I go about designing this? Should I make an interface that has all my database calls? Something like this? GetUser(); InsertUser(); ...

LinqDataSource and DateTime Format

I'm trying to create a LinqDataSource to bind to a DropDownList in an ASP.NET form. I only want to show the elements according to a date (which is one of the fields in the database). Basically, the elements I want to show are the ones that will happen in the futures (i.e. after DateTime.Now). I was trying the following markup : <asp:...

Is there a way to find a table in a DBML file in Visual Studio 2008?

This ones been bugging me for ages. Back in the olden days when we hunted our own food and used DataSets, you could snap to a particular table in a DataSet by selecting what you want from a drop down list at the top. If I have a big ol' Linq2Sql DBML file with lots of tables in it, it becomes a nightmare to navigate around. Is there a ...

How do I run a stored procedure once per class hierarchy update in LINQ?

I have two related tables in my database: Page and Tag. One Page can be related to many Tags. Whenever either of these two tables is modified, a stored procedure called BeforePageHierarchyUpdate needs to be executed (in my case this stored procedure performs some logging and versioning on the Page hierarchy). What's giving me problems...

LINQ to SQL Violation of UNIQUE KEY constraint with NULL column

I have the following table. When i try to insert records using LINQ to SQL it works fine until I try to insert a record where the UserId is null. When I try that I get the following error "UNIQUE KEY constraint Cannot insert duplicate key in object" I am only trying to insert 1 record and the table is empty so there is definitely no cl...

LINQ to SQL : Delete a new added child entity before submitchanges - fails

Hello, I have a parent child relationship very similar to Northwind Customer/Orders but with one differnece , CustomerID in Orders table can not accept NULL , it is a FK , the child has one column PKey called OrderID I use this model in a windows forms databinding , upper area is having customer info in text boxes , lower area is havin...

With LinqtoSql, when/how does it map your objects to tables?

With LINQ To SQL, how/when does the process map your object/entity to your table? Does it create its own ADO.NET code under the hood? Is it strongly typed? Are the SQL parameters taking column size/type into account? (nvarchar 500, etc.) ...

LINQ to MySql Data Provider

Hi, After a quick Google I couldn’t find anything too promising so I was wondering if anyone knew if there is a good/widely used LINQ to MySql Data Provider out there? ...

Split string in Linq select statement

I tried to split a string in a linq query. I got an error says "Unrecognized expression node: ArrayIndex". Does anyone know how to achive this? My code sample is: List<Task> Result= (from t in TaskDB.Tasks select new Task { ...

How do I create a generic DataContext factory?

I'm building a generic Repository<T> class that supports Linq to SQL, and I'd like to use a factory pattern for the DataContext, because currently I have to pass the correct context to the constructor. Does anybody know how to determine the correct DataContext type for T, where T is a Linq to Sql Table? ...

Populating Models using LINQ

I'm trying to figure out a clear way of populating my model classes from LINQ to SQL generated objects. My goal is to keep my Models and LinqModels separate. Say I have the following models: public class Person { public List<Account> Accounts {get; set;} } public class Account { public List<Purchase> Purchases {get; set;} } pub...

Using LINQ to delete child records automatically

I am somewhat new to LINQ and have a quick question regarding deleting. Say, for example I have 2 tables, Orders and OrderItems. Using LINQ, I can easily create a new child record by using order.Items.Add(new OrderItem()); and this will create the child record in the database and update its foreign key to the orderId. This is great...

Is the Entity Framework out yet?

Since LinqToSql has been replaced by the Entity Framework, is the Entity Framework out yet? ...

Is there a way to get a fully executable string of the SQL that is about to be run by a Linq2Sql expression?

I know you can get the SQL, but it's paramterized without the parameters being visible. Can you get the "full" string, so to speak? ...

Caching ListView data a viable option?

Here's my scenario: 1) User runs search to retrieve values for display in ListView via LinqDataSource. 2) They click on one of the items which takes them to another page where the details can be examined, further drill-down can happen, etc. 3) User wants to go back to the original ListView results to select another item for inspection. ...

Updating LinqDataSource from separate DataContext

I want to update one LinqDataSource with a record retrieved from a different DataContext. The problem is that the DataContext of the LinqDataSource doesn't seem to be made public so I can't get access to it to attach the new object to the DataSource's context. What is the normal way of doing this? Or should I just scrap the LinqDataSou...

Using SqlServer uniqueidentifier/updated date columns with Linq to Sql - Best Approach

Rightly or wrongly, I am using unique identifier as a Primary Key for tables in my sqlserver database. I have generated a model using linq to sql (c#), however where in the case of an identity column linq to sql generates a unique key on inserting a new record for guid /uniqueidentifier the default value of 00000000-0000-0000-0000-000000...

Linq To SQL : Modeling Associations

I have three tables Projects, Users and ProjectMembers. The ProjectMembers table is a mapping table and has only two columns ProjectId and UserId. In my object model i have two classes Project and User. The Project class has a property IEnumerable<User> Members I am using an external xml map file for mapping linq to sql associations. I...

How do you sort an EntitySet<T>

The MSDN documentation states that an EntitySet implements IBindingList (see 'Binding to EntitySets' at http://msdn.microsoft.com/en-us/library/bb546190.aspx) However, it can be clearly seen that an EntitySet does not implement this interface! So how do I sort? For context, I'm binding this set to a WPF ListView. For wider context o...

LINQ to SQL -- Can't modify return type of stored procedure.

When I drag a particular stored procedure into the VS 2008 dbml designer, it shows up with Return Type set to "none", and it's read only so I can't change it. The designer code shows it as returning an int, and if I change that manually, it just gets undone on the next build. But with another (nearly identical) stored procedure, I can...