linq-to-sql

Why can't I open the same database files (.mdbs) in multiple environments at the same time?

This kind'a sucks. If I connect to a SQL Server DB (.mdb file) through VS.Net's server explorer, then I can't connect to the same file via SQL Server 2008 Management Studio at the same file. The file is locked. For example, I get the following error from SQL Server Management Studio CREATE FILE encountered operating system error ...

How To add another constructor with parameter in linq class(Table)

Hi, I am using LINQ to SQL in an ASP.NET project. While inserting the table I need to convert the values to the particular table object and I need to insert. For that I created a new constructor in that table with parameter so that I can assign my value to that table object , the assign the functionality is working but while inserti...

C# Linq Delete over Join

Hello, I have a Question table which joins to a Solution table. The solutions are linked to the questions but in order to delete a question, i must delete the solutions for that question first and then delete the question itself. I have a linq query that retrieves all solutions for a specified question however i am unsure how to proceed...

DeleteOnNull (Association attribute) for Linq to SQL in custom class?

Is it possible to add the "DeleteOnNull=true" on a custom class instead of modifying the DBML (generated) class directly? For example, let's say this is a part of my generated dbml class: [Table(Name="OrderDetails")] public partial class OrderDetail : INotifyPropertyChanging, INotifyPropertyChanged { // deleted for brevity ...

How do I resolve multiple linq queries in one operation without using a base query?

I have 14 LINQ queries to resolve in one method. None of them have a base query that I could hang them from as subqueries and then store the results as properties of an anonymous type instance. Rather than making 14 separate calls to the database, how can I ensure that they are all called in the same operation? UPDATE I ended up using...

Would this SingleOrDefault() optimization be worthwhile or is it overkill / harmful?

I was messing around with LinqToSQL and LINQPad and I noticed that SingleOrDefault() doesn't do any filtering or limiting in the generated SQL (I had almost expected the equivalent of Take(1)). So Assuming you wanted to protect yourself from large quantities accidentally being returned, would the following snippet be useful or is it a...

How do I update a SQL row given an ID with LINQ to SQL?

Given this schema: Fruits - FruitID INT PK - FruitName NVARCHAR(30) - FruitStatusID INT NULL FK: Statuses Statuses - StatusID INT PK - StatusName NVARCHAR(30) If I have a FruitID in hand (just an int, not a Fruit object), how do I update the FruitName and null out FruitStatusID without loading the Fruit object ...

Resources for learning LINQ?

I'm looking to learn LINQ, but I'm finding that there is a lot more to it then what I initally expected. In fact, there's so much that I'm not sure where is the best place to start. I know that there's LINQ to SQL, and LINQ to Entities, and a number of other LINQ whatevers out there. Which is the best to start with? It seems that I see ...

Linq sql data binding to winforms combobox

I am trying to bind a ComboxBox to a foreign key table. I know that on cannot bind to the actual foreign key, SomeTableClassFK, (causes a LinqSql exception when the FK already has a value). So, I am binding to FK object, SomeTable, reference thru the SelectedItem property of the ComboBox. SomePrimaryTable SomeTableClassFK ---> SomeT...

How to create a LINQ To SQL datacontext for large DB using SQLMetal when it generates a 12MB DataContext.cs file?

My problem is this: We have a very large Legacy DB with many SPROCs, Views & Tables. The Designer is a "NO GO" b/c of the size. I've configured SQL Metal to build the data context, but the resulting code file is so big (12MB) visual studio 2008 will not open it. If SQLMetal would generate a new file for each class type (Table, View,...

Can you Obfuscate LinqToSql Assemblies with .net reactor without breaking them?

I am using .net Reactor to obfuscate a data layer assembly containing LinqToSql classes. On invoking the assembly, i am getting the following error.. Bad Storage property: '_ApplicationId' on member 'RCSQLData.Application_DB.ApplicationId' I am using the 'Library' mode and have enabled 'Necrobit' and 'obfuscation'. Is it possible to ...

How to do SQL Like % in Linq?

Hello All, I have a procedure in SQL that I am trying to turn into Linq: SELECT O.Id, O.Name as Organization FROM Organizations O JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId where OH.Hierarchy like '%/12/%' The line I am most concerned with is: where OH.Hierarchy like '%/12/%' I have a column that stores the hierarch...

Visual Studio and LINQ: placing the DBML file in separate directory in the project

My strategy was to keep the project's layout clean. Given that this is a datalayer project, and I'll have a class file for each concerned entity, I thought I would put the .dbml into its own directory. It turns out that locating your .dbml file within a subdirectory turns it into a lower level namespace of sorts. This is a C# class libr...

Concurrency with Linq To Sql Stored Procedures

I come from the asp.net world where we'd use an objectdatasource, hooked up to data access layer, and set it's ConflictDetection property to "CompareAllValues". There is an OldValuesParameterFormatString on the ObjectDataSource that you use to identify old value parameters. The sql procedure that does an update would then require both n...

Should my DAL return DataTables or I...whatever<>?

EDIT 1 I apologize but after reading the 2 suggested articles I still don't understand what I should use. I understand that using IQueryable is not preferred for various reasons but does that eliminate IEnumerable as well? Is a DataTable really my best option? In short, I guess, what is the preferred Return type? I have the followi...

To linq To SQL or not... that is the question?

Our team is now beginning to look at jumping from 2.0 to 3.5 and have been reviewing all the new stuff.... So, with the whole Linq to SQL not being heavily improved in the future should we ignore it completely? It seems that it may fit of our needs very well BUT I imagine so could entity framework even if it may add more complexity. S...

Response class when LINQ To SQL call stored procedure

Hi All, I have a little project, it is using LINQ and SP, I would like to create a response class which return information after i called SP. I saw on this page a solution (http://stackoverflow.com/questions/307656/rollback-a-stored-procedure-call-from-inside-a-transaction-using-linq-to-sql) but i don't know how look like this Response ...

What causes Timeout expired SqlExceptions in LINQ to SQL?

My application keeps running into Timeout Expired SqlExceptions. The thing is that this query is one that will simply have to run for a decent amount of time. I'm having trouble figuring out where this exception is occurring though. Is this a timeout that's created at the database server or is it happening in my program? Or if it cou...

Static methods vs repository pattern with Linq2Sql

I've hit on the idea of creating static methods on the partial Linq queries such as public partial class User { public static User FindByGuid(string guid, ApplicationDataContext context) { return context.Users.Where(x => x.GUID == guid).Single(); } } So, for example, I can easily find a user by doing: using (var c...

How can I tell if a given Linq-to-Sql object is attached to a datacontext?

I use linq 2 sql for my ORM. For performance reasons, I serialize some of them, and throw them into memcached. When they're deserialized, they're of course not attached to a datacontext, which is 100% fine, as they're only used for reading from in those scenarios. For sanity reasons however, I'd like to be able to tell whether a gi...