linq-to-sql

LINQ to SQL A member defining the identity of the object cannot be changed.

Hi, I'm writing a Generic for LINQ to SQL CUD. I 'Generic Insert Public Shared Sub Add(Of T As Class)(ByVal entity As T) Using db As New APIUDataContext() db.GetTable(Of T)().InsertOnSubmit(entity) db.SubmitChanges() End Using The genric Insert is working good. 'Generic Update Public Shared Sub Update(Of...

Linq to Sql DataContext life cycle in a WCF service

Hi, I have a service exposed via WCF. The service exposes several methods that talk to the database through a Linq to SQL datacontext. The datacontext is bound to the CallContext. All of this is working as it should but I can't figure out the proper place to dispose the Linq to SQL datacontext. Please help. ...

Multi-threading with Linq to SQL

I am building an application which requires me to make use of DataContext's inside threads. My application keeps throwing InvalidOperationException's similar to: There is already an open DataReader associated with this Command which must be closed first ExecuteReader requires an open and available Connection. The connection's current s...

New .NET 3.5 Project: Which DAL technology to use?

Hello, I am preparing a new Windows project and wonder what kind of DAL technology to use. Originally I was looking for something simpler to not spending too much time on building it. But I understand also that it has to be efficient and scalable in the long run. I plan to use WPF (MVVM) Client and WCF Service on a 3 Tier system. Just...

EntityFramework or LinqToSql Entity Namespace

Hi, I want to specify entity namespace based on my domain structure. Usually like that : Infrastructure.SqlServer Customers (NS : Infrastructure.SqlServer.Customers) Customer Address Products (NS : Infrastructure.SqlServer.Products) Product ProductVariant ProductCategory How can i do that with LinqToSql or EntityFramework ? It...

Linq to SQL with Stored Procedures

I want to add custom (compound and read-only) attributes to my stored procedure results class. When I did that, I got the error LINQ - Cannot assign value to member XXX. It does not define a setter. I then found this blog post - the author suggests that decorating the partial class with the [Table] attribute will resolve the problem. ...

Binding a ComboBox using a DataContext and LINQ to SQL

I have a simple SQLite database I use to track invoices. I recently decided to write an application for it as an excuse to learn LINQ. I found other questions that address this issue, but none of the solutions worked for me. Using the O/RM designer, I modeled my database similar to the following (simplified): +------------+ ...

How to store results of a LINQ To SQL query in memory

Hi, I was wondering how I can pull down a portion of a table using LINQ To SQL into C# memory space. Let's say I have a database with thousands of records and a GUI interface that shows one record at a time. When the user clicks the next / previous record button on the GUI the LINQ To SQL datacontext has to go and get the next record - ...

Linq-Sql IQueryable<T> and chaining OR operations

I'm trying to simulate: WHERE x.IsActive = true OR x.Id = 5 The following causes 'AND' to be used... how do I simulate an 'OR' condition with IQueryable (qry) and my nullable int, given that other filtering might be involved as with the IsActive filter here? if (onlyActiveItems) //bool { qry = q...

DataLayer in Linq with different version of Data model

Hi, I wanted to ask the SO community about this problem in my project. I have a Silverlight App Project in SL 3.0, which at the moment has a classic design with a business layer and a data layer in Linq2SQL. The problem is that the Data model can be in different version with some little changes in between. I have 2 solutions but neith...

How can I create a LINQ-to-SQL statement when I have table name as string?

If I have the name of a database table like this: string tableName = "Addresses"; string tableName = "Customers"; How can I construct a dynamic LINQ statement like this: var items = from o in db.{tableName} select o; foreach (var item in items) { sb.Append(item.Id + Environment.NewLine); } I know I could do something like t...

Use strongly typed data rather than a string to bind to a drop down list

Given the following class.... namespace IMTool.Data { public partial class AllContracts { internal class Metadata { public int ContractId { get; set; } [Required] public string Name { get; set; } } } } and given the following. using (var context = new IMToolDataC...

Comparing IPAddress (stored as varbinary)

I have an IPAddress column on my Activity table. This is stored as a varbinary(16) so that it can be efficient (moreso than storing as a string) and also support IPv6. When I store, I basically get the value of (new System.Net.IPAddress("127.0.0.1")).GetAddressBytes(). What I want to be able to do is search for all IP addresses that beg...

Atomically mark and return a group of rows in database

I'm writing a background service that needs to process a series of jobs, stored as records in a sqlserver table. The service needs to find the oldest 20 jobs that need to be worked (where status = 'new'), mark them (set status = 'processing'), run them, and update the jobs afterward. It's the first part I need help with. There could be ...

Why won't this LINQ TO SQL query come back in the right order?

(from assetVisit in AssetVisits join assetBundle in AssetBundles on assetVisit.AssetID equals assetBundle.AssetID join groupBundle in GroupBundles on assetBundle.BundleID equals groupBundle.BundleID join userGroup in UserGroups on groupBundle.GroupID equals userGroup.GroupID where assetVisit.CompanyID ...

Dynamically Modifying a LINQ to SQL Select Statement's Columns

Hello, I'm trying to build a REST-ful API for my app. Currently I have something like this: www.example.com/submissions/?format=json This will return latest ten submissions in JSON. Each object has its details, such as submission name, date created, user, body, etc. I'd like to do something such as: www.example.com/submissions/?format...

LINQ to SQL query not ordering properly, please help.

var temp = (from assetVisit in db.AssetVisits join assetBundle in db.AssetBundles on assetVisit.AssetID equals assetBundle.AssetID join groupBundle in db.GroupBundles on assetBundle.BundleID equals groupBundle.BundleID join userGroup in db.UserGroups on groupBundle.GroupID equals userGr...

Confirming a successful LINQ to SQL update

I am using LINQ to SQL. Is the following code proper if I want to notify the sender that the database was updated successfully or is there a better way? try { dc.ModelA.InsertOnSubmit(modela); dc.SubmitChanges(); return true; } catch { ...

Use LINQ generated classes directly?

LINQ will generate a set of classes from the SQL files. Should these be used directly, or should they be wrapped in another class so the model is not so dependent on the implementation? ...

Is there any way to profile .NET Framework?

We have a complex client-server application that is developed using .NET Framework and uses SQL Server 2005. We use LinqToSql but we manage the life time of all the connections and we pass open connections to any DataContext that gets created. We've also used Microsoft WF in this product. WF makes its own connections to persist workflow...