linq-to-sql

Strange behaviour with StructureMap / ASP.MVC / Visual Studio / LinqToSql

I have been using the new MVC framework with StructureMap recently and have had good results overall, however, I keep running into a very strange error that I cannot understand or work out how to resolve. This is my architecture: DBContext - linqToSql data context. IRepository - contract defining data methods. IService - contract def...

Linq2Sql: Help with SqlException about UNION, INTERSECT and EXCEPT

Could someone help me with this exception? I don't understand what it means or how to fix it... It is an SqlException with the following message: All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists. I get it when running a query in psudo code looking like t...

How do I make a 'ReadOnly' property in LINQ to SQL?

I have a property ("IsLatest") that I have set 'Read Only' to 'True' Here's the XML: <Column Name="IsLatest" Type="System.Boolean" DbType="Bit NOT NULL" IsReadOnly="true" CanBeNull="false" /> Why does the code-generator generate a public 'get' AND 'SET' accessor? Also, is there a way to have it not generate a SET for a read-only pro...

How to trim values using Linq to Sql?

In the database, I have a table called Contact. The first name and other such string fields are designed to use a Char datatype (not my database design). My object Contact maps to a string type in the properties. If I wanted to do a simple test retrieving a Contact object by id, I would do something like this: Contact contact = db.Co...

Domain Driven Design (Linq to SQL) - How do you delete parts of an aggregate?

Hi All I seem to have gotten myself into a bit of a confusion of this whole DDD\LinqToSql business. I am building a system using POCOS and linq to sql and I have repositories for the aggregate roots. So, for example if you had the classes Order->OrderLine you have a repository for Order but not OrderLine as Order is the root of the aggre...

LINQ to SQL pitfalls

What are the major pitfalls that would make you think twice about using LINQ to SQL in an enterprise/non-trivial system? I know it lacks the power and flexibility of NHibernate, but I'm not clear on the major reasons why you wouldn't want to use LINQ to SQL in an enterprise app. ...

C# How to convert an Expression<Func<SomeType>> to an Expression<Func<OtherType>>

I have used C# expressions before based on lamdas, but I have no experience composing them by hand. Given an Expression<Func<SomeType, bool>> originalPredicate, I want to create an Expression<Func<OtherType, bool>> translatedPredicate. In this case SomeType and OtherType have the same fields, but they are not related (no inheritance and...

How do I translate this GROUP BY / MIN SQL query into LINQ?

I plan on using this in a subquery but can't figure out the correct syntax to translate the following query into LINQ: select ChapterID, min(MeetingDate) from ChapterMeeting group by ChapterID ...

linq to sql batch delete

Hi. I have the following DB: Posts which have an Id, Tags also with Id, and TagsToPosts table which have TagsToPosts.PostId => Posts.Id and TagsToPosts.TagId => Tags.Id FK relations. I need to delete multiple items from TagsToPosts in following way. I'm creating IList<Tag> newTags by parsing a string. Each tag have it's name. I want to d...

Linq to SQL - double quote issue

I have a problem wherein if I have a text area in ASP.NET and enter 2 double quotes at the very end of the sentence, I get a error in my sql statement. I have traced thru the sql profiler but with no luck. eg. The lazy fox jump over the dog"". This fails.... ""The "lazy" fox jumps over the dog. This seems fine Any pointers most welcom...

How do I do queries against hierarchical data using LINQ to SQL?

I have 2 tables that are related. each app can relate to many apps. ie, office can be related to word, excel....... app id PK int appname varchar(50) ..... appsrelated relatedid int fk to app.id appid int sample data app id, appname 1, office 2, word 3, excel 4, quake appsrelated relatedid, appid 1, 2 1, 3 basically new to linq t...

Data Access Layer newbie

Newbie to .NET data apps here, coming from a Visual Foxpro background. I'm planning on an ASP.NET and/or Silverlight UI, and maybe some WPF client stuff too on our LAN too, so I want to craft a data access layer that can support all these front ends. My data will be in SQL server. I have already made a test run of pushing the data from...

In a datacontext are inserted values not available within the datacontext until after submitchanges?

I'm going through an XML file of articles and the journalist(s) that wrote them. As we are adding the articles into _Data our datacontext we may come across a journalist that needs adding so we do this: newJourno = New journalist With {.name = strJournalist} _Data.journalists.InsertOnSubmit(newJourno) .articles_journalists.Add(New artic...

LINQ to SQL doing a Union and Left Outer Join

I have 3 tables. 2 contain lists of files that I need to do a UNION on to get all the unique files, then I want to do a left outer join against the 3rd table to find all the files that are in the 3rd table only and not in the other 2. To do the UNION I have the following: var imageUnion = (from img in dc.ImageT1 selec...

LinqToSql strange behaviour

I have the following code: var tagToPosts = (from t2p in dataContext.TagToPosts join t in dataContext.Tags on t2p.TagId equals t.Id select new { t2p.Id, t.Name }); //IQueryable tag2postsToDelete; foreach (Tag tag in tags) { Debug.WriteLine(tag); tagToPosts ...

Linq To Sql - ChangeConflictException not being thrown. Why?

I am trying to force a ChangeConflictException by altering records in two different browsers. This has worked for me in the past. But now it just wont throw the exception. Last one in is winning. I have checked the column properties of the entity I am updating and each column is set to always check. Is there anything I can look for? ...

Concurrency with Linq To Sql and ASP.NET

What is the best way to check for concurrency issues when using LINQ to SQL in an ASP.net application. In my application, I am retrieving a record from the database and displaying the fields in editable textboxes. Then the datacontext is thrown away. How should I save the entity object so that I can use L2Sql's built in concurrency fea...

Is there a sImple way to tell if a LINQ to SQL record has been changed?

I've got a simple routine that populates a record in a table. I have fields that I only want to update if an actual change has taken place. The function could get called even if the user did not change anything. Is there an easy way to tell if changes have taken place? Here's the function: Sub Edit(ByVal key as Integer, ByVal myval1 As ...

Linq to Sql, retrieving nested data structures with one query

I'm not sure if an answer for this already exists, as I can't figure out what mechanism in Linq is meant for this situation, or if I just need to do it manually. Let's say I have 2 tables: ------------Employees------------- EmployeeID Name -other columns- ---------EmployeeSkills----------- EmployeeID Skill -other columns- ...

ChangeConflictException in Linq to Sql update

I'm in a world of pain with this one, and I'd very much appreciate it if someone could help out. I have a DataContext attached to a single test table on a database. The test table is as follows: CREATE TABLE [dbo].[LinqTests]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [StringValue] [varchar](255) NOT NULL, [DateTimeValue] [dat...