linq-to-sql

LINQ-to-SQL + One-to-Many + DataBinding deleting problem

I use LINQ-to-SQL to load data from a database that has two tables in a one-to-many relationship (one Recipe has many Ingredients). I load a Recipe and LINQ retrieves Ingredient objects into an EntitySet that is binded into a ListBox. If I want to delete some Ingredients off a Recipe, I get a "An attempt was made to remove a relationsh...

Techniques to monitor/improve performance in Linq to Sql queries

I have a webpage that is taking way too long and need to optimize it. Because uninformed optimizing is the devil, I need to know what exactly is holding me down. A quick glance showed me that it is probably an sql2linq query that is most likely causing the trouble. What are techniques of pinning the performance problem in this case? Are...

Correctly incrementing values using Linq to SQL

I have a MS SQL table that I don't have any control over and I need to write to. This table has a int primary key that isn't automatically incremented. I can't use stored procs and I would like to use Linq to SQL since it makes other processing very easy. My current solution is to read the last value, increment it, try to use it, if I g...

Linq-to-Sql SubmitChanges not updating fields ... why?

I posted this question yesterday evening, which has led me to discover a huge problem! I have a decimal column in my database called Units, anytime I set the value of the column to a NON ZERO, and SubmitChanges the column updates with the new value. If I try to set the value of the column to ZERO, the SubmitChanges does not update the ...

Regex Replace to assist Orderby in LINQ

I'm using LINQ to SQL to pull records from a database, sort them by a string field, then perform some other work on them. Unfortunately the Name field that I'm sorting by comes out of the database like this Name ADAPT1 ADAPT10 ADAPT11 ... ADAPT2 ADAPT3 I'd like to sort the Name field in numerical order. Right now I'm using the Regex...

Outer Joins and Linq

So I have the following code: return from a in DBContext.Acts join artist in DBContext.Artists on a.ArtistID equals artist.ID into art from artist in art.DefaultIfEmpty() select new Shared.DO.Act { ID = a.ID, Name = a.Name, Artist = new Shared.DO.Artist ...

DLINQ- Entities being inserted without .InsertOnSubmit(...)?!

Hello, I ran into an interesting problem while using DLINQ. When I instantiate an entity, calling .SubmitChanges() on the DataContext will insert a new row into the database - without having ever called .Insert[All]OnSubmit(...). //Code sample: Data.NetServices _netServices = new Data.NetServices(_connString); Data.ProductOption[] te...

How can I speed up this linq to sql function?

I have a function (called "powersearch", the irony!) that searches for a set of strings across a bunch(~ 5) of fields. The words come in as one string and are separated by spaces. Some fields can have exact matches, others should have "contains". (Snipped for brevety) //Start with all colors IQueryable<Color> q = db.Colors; //Filter ...

How to create a dynamic Linq Join extension method

There was a library of dynamic Linq extensions methods released as a sample with VS2008. I'd like to extend it with a Join method. The code below fails with a parameter miss match exception at run time. Can anyone find the problem? public static IQueryable Join(this IQueryable outer, IEnumerable inner, string outerSelector, string in...

LinqToSQl and adapting from linq to Domain objects in a centralised manner

Imagine the following code: return from a in DBContext.Acts join artist in DBContext.Artists on a.ArtistID equals artist.ID into art from artist in art.DefaultIfEmpty() select new Shared.DO.Act { ID = a.ID, Name = a.Name, Artist = new Shared.DO.Artist { ...

When should I dispose of a data context

I'm currently writing a data access layer for an application. The access layer makes extensive use of linq classes to return data. Currently in order to reflect data back to the database I've added a private data context member and a public save method. The code looks something like this: private DataContext myDb; public static MyClass ...

Would you use LINQ to SQL for new projects?

I've been investigating what data layer to use for a new web-based project I'm designing and I'm very keen to look at incorporating LINQ to SQL. Its apparent simplicity, flexibility and designer support really appeals and the implicit tie-in to SQL Server is fine. However, it has been announced recently that LINQ to SQL will be taking a...

Stackoverflow's Related Questions

Just wondering how you would go about implementing something similar to stackoverflow'd related questions. Would you simply match the tags, match similar words in the titles, or words in the entire question? Particular interested in a linqtosql method. Cheers! ...

How can I add my attributes to Code-Generated Linq2Sql classes properties?

Hi I would like to add attributes to Linq 2 Sql classes properties. Such as this Column is browsable in the UI or ReadOnly in the UI and so far. I've thought about using templates, anybody knows how to use it? or something different? Generally speaking, would do you do to address this issue with classes being code-generated? ...

Adding related data with multiple LINQ to SQL DataContexts

Hi: I'm developing a desktop application using Linq to SQL. From what I've gathered, it's better to keep DataContext objects short-lived, but I'm running into the following puzzle: My application has lots of lookup-type data that I'd like to cache on the client. The reason I want to cache it is because I don't want to have to look up...

Linq to SQL Class

Hi, I have a Class see below, when i am trying to query it from another page it not linking e.g. if i put "var Notes = HandhedNotes.GetNotesByLinkIDJoin();" when i look at Notes theres not links there. I think its due to the IQuerable maybe I should be using something elese?? namespace WebSys { public partial class HandheldNote { ...

Update without first selecting data in LINQ 2 SQL?

How can you go about updating a record without having to select the data first in LINQ? As you must first perform a linq select (obviously calls a SQL SELECT which is costly), change required properties, then perform SubmitChanges(). I wish to avoid this and just perform a SQL UPDATE, I already know the ID. ...

linq2sql missing event model?

How come the "Table" classes Generated in the Dbml do not contain useful events like OnBeforeInsert OnBeforeUpdate OnAfterInsert etc. Am I missing something? This question is related to frustration trying to set timestamp columns. UPDATE I created the following method of doing this neatly what does everyone think? public class M...

Linq2Sql Testing

I have test database and a production database. When developing I of course work against that test database then when deploying I have to semi-manually update the production database (by running a batch-sql-script). This usually works fine but there's a chance for mistakes where the deployed database isn't the same as the test database. ...

How can I maintain child objects with LinqToSql over WCF?

I am currently stuck in the design of this solution. The data layer design consists of the following: Recipe (parent high level object) Language Detail (name, description by language) (many) Headers (many) Steps (many) Ingredients (many) Quantities (many) Procedures (many) Notes (many) The challenge that I am having is how to ...