linq-to-sql

linq image saving problems

I have an object that has a property: [Column] public Binary Image { get; set; } When the object is saved the first time every this is OK, but when it is modified I get an exception on SubmitChanges: The data types image and varbinary(max) are incompatible in the equal to operator. What might be the problem here? ...

first time I have to create an extension for linq2sql, how to do this one?

I have this one line property Public ReadOnly Property DateToUniversal(ByVal dt As Nullable(Of Date)) As String Get Return If(dt.HasValue, dt.Value.ToString("u").Substring(0, 10), "") End Get End Property if i'm trying to use that into a from n in mydatacontext select new myObj {n.field1,n.field2, DateToUniversal(n....

Site update, testing was fine, after deployment, again fine, once user load increases, FAIL?

We are using ASP.NET MVC with LINQ to SQL. We added some features and tested them all to perfection on our QA box. We are using Windows Server 2003 and SQL Server 2005. So when we pushed out changes to the Live web server we also used Red Gate SQL Compare to push new database changes to the LIVE database. We tested again between the few ...

In LINQ to SQL based Repositories, should we create a new DataContext within each method?

for example: class repository { private DataContext db = new DataContext(); public IQueryable<Blah> someMethod(int id){ return from b in db.Blah ... select b; } public IQueryable<Blah> someMethod2(int id){ return from b in db.Blah ... select b; } public IQueryable<Blah> someMethod3(int id){ ...

Linq to SQL Extensibility Method Definitions

If I have a Linq table of say User and I then do something like this; public partial class DataAccessDataContext { partial void UpdateUser(User instance) { //do something here } } What ends up happening is that the record is never updated in the database. As soon as I get rid of the UpdateUser method the database ...

LINQ to SQL Table Extensibility Methods

If I have a LINQ to SQL table that has a field called say Alias. There is then a method stub called OnAliasChanging(string value); What I want to do is to grab the value, check the database whether the value already exists and then set the value to the already entered value. So I may be changing my alias from "griegs" to "slappy" and ...

How can I get items that their names start with a number in Linq To Sql?

How can I get a list of Products that, for example, theirs productName starts with a number? Thanks!! ...

How do I get a linq to sql group by query into the asp.net mvc view?

Sorry for the newbie question, but I have the following query that groups parking spaces by their garage, but I can't figure out how to iterate the data in the view. I guess I should strongly type the view but am a newbie and having lots of problems figuring this out. Any help would be appreciated. Public Function FindAllSpaces() ...

Why should i use LINQ to SQL when ADO.NET works better than this

Why should we use LINQtoSQL when ADO.NET is giving us better performance? Checkout this link which shows the comparison reports I am looking for Speed /Performance of my application rather than deployment easiness. Is there anything else which should we considered before i leave LINQ to SQL and go back to my OLD ADO.NET DataAcces Layer...

Learn LinqToSql or stick with ADO.NET?

I'm debating what technology to use for an upcoming ASP.NET project. Assumptions: I will be using Visual Studio 2008 SP1 (.NET Framework 3.5) The back-end will be a SQL Server 2005 database (or possibly 2008) Code will be written in C# I already have experience with LinqToObjects and LinqToXml I also have experience with ADO.NET and s...

What's the difference between these two LINQtoSQL statements?

These two statements look the same logically to me, but they're resulting in different SQL being generated: #1 var people = _DB.People.Where(p => p.Status == MyPersonEnum.STUDENT.ToString()); var ids = people.Select(p => p.Id); var cars = _DB.Cars.Where(c => ids.Contains(c.PersonId)); #2 string s = MyPersonEnum.STUDENT.ToString(); va...

How to run a mass update/delete query in Linq?

I have 2 Linq2Sql classes: Parent and Child. I want to do things like removing all children for a parent, or updating all child records. In SQL I would have written: delete Child where ParentID = @p or update Child set Val = Val+1 where ParentID = @p I can do this in Linq the brute force way inside the Parent class: Children.ToL...

Custom LINQ expression Gridview Bind

Hello all. I am following the good old Scott Gu LINQ to SQL guide to LINQ and have stumbled upon a query. Here is my scenario. I have a textbox a client should populate with a number (tbxHowMany), two radio buttons that define a material (radPaper & radGlass). A also have a button (btnReturn) that when clicked, a gridview (gridview1) ...

Linq to SQL VarChar(Max) Update is not working

I am not able to get an update to work using Linq to SQL on a VarChar(Max) field. Here is the code I use that is called from a simple DAO class: public void UpdateContentById(int ContentId, string Content) { CkEditorDataContext db = new CkEditorDataContext(); CkEditorContent dbContent = db.CkEditorContents.First(c => c.CkeId == ...

Linq2Sql Entity class cannot be serialized after adding an association.

I am making ajax calls to my webservice (using MS ajax framework - Telerik comps uses it actually). I am returning one of the Entity classes generated by the dbml. It used to work fine, but when I added the associations it started throwing an exception on the server, saying "a circular reference was detecting when serializing type " I w...

C# MVC ViewModel Property OrderBy Exception

I have a collection of ViewModel objects that I am attempting to sort. This is an abbreviated view of my ViewModel class: public class BookIndexFormViewModel { //Properties public Book Book { get; set; } //Constructor public BookIndexFormViewModel(Book book) { Book = book; } Thi...

How to make linq to sql classes internal or private?

I found this question/answer about setting linq to sql classes as internal, but one thing I found is that classes generated for stored procedure return types are set as public, and even though I set the access modifier for the stored procedure and the data contest class as internal, the generated class for the stored proc is still public...

Is SqlMetal a good solution for mapping to a database that contains *only* tables?

I'm thinking of using SqlMetal to auto-generate LinqToSql code for a simple and small database. The database will have only tables with some primary and foreign keys (i.e., no views, stored procedures, functions, etc.). I'd like to do all joins, grouping, sorting, and advanced data manipulation using Linq. I have experience with LinqToO...

Convert Image Datatype in sqlserver to Byte[] in Linq anonymous object

Hello, I'm facing problem while converting image datatype to byte[]. Please give me a solution for this. Thanks in advance. Susan. ...

Disposing datacontext causes Invalid attempt to call Read when reader is closed

I'm building an MVC 2 app and using linq to sql with stored procs. I created a data access layer that has an internal datacontext class and a public class that I expose applications. In my public class I expose methods which access the datacontext class and convert the data to my own object model classes using linq. In my public class...