linq-to-sql

How to load Many to many LINQ query?

Hi. I have the following (pretty standard) table structure: Post <-> PostTag <-> Tag Suppose I have the following records: PostID Title 1, 'Foo' 2, 'Bar' 3, 'Baz' TagID Name 1, 'Foo' 2, 'Bar' PostID TagID 1 1 1 2 2 2 In other words, the first post has two tags, the second has one and the third one...

Should I start using LINQ To SQL?

Currently I am using NetTiers to generate my data access layer and service layer. I have been using NetTiers for over 2 years and have found it to be very useful. At some point I need to look at LINQ so my questions are... Has anyone else gone from NetTiers to LINQ To SQL? Was this switch over a good or bad thing? Is there anything tha...

Is there a way to override the empty constructor in a class generated by LINQtoSQL?

If I have a table in my database called 'Users', there will be a class generated by LINQtoSQL called 'User' with an already declared empty constructor. What is the best practice if I want to override this constructor and add my own logic to it? ...

Limiting results of System.Data.Linq.Table<T>

I am trying to inherit from my generated datacontext in LinqToSQL - something like this public class myContext : dbDataContext { public System.Data.Linq.Table<User>() Users { return (from x in base.Users() where x.DeletedOn.HasValue == false select x); } } But my Linq statement returns IQueryable which cannot cast to Table - does...

LINQ to SQL in Visual Studio 2005

I normally run VS 2008 at home and LINQ is built in. At work we are still using VS 2005 and I have the opportunity to start a new project that I would like to use LINQ to SQL. After doing some searching all I could come up with was the MAY 2006 CTP of LINQ would have to be installed for LINQ to work in VS 2005. Does someone know the p...

Debugging LINQ to SQL SubmitChanges()

I am having a really hard time attempting to debug LINQ to SQL and submitting changes. I have been using http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx, which works great for debugging simple queries. I'm working in the DataContext Class for my project with the following snippet from my application:...

Does LINQ-to-SQL Support Composable Queries?

Speaking as a non-C# savvy programmer, I'm curious as to the evaluation semantics of LINQ queries like the following: var people = from p in Person where p.age < 18 select p var otherPeople = from p in people where p.firstName equals "Daniel" select p Assuming that Person ...

Entity Framework - Can you map the result type of an imported stored procedure to a custom entity type?

I already have an entity model in a separate dll that contains various objects that I need to use. I don't really want to create or duplicate entities using the EF designer. Instead I would like to configure it so that when I call a stored procedure it will map certain columns to specific properties. I know you can do something VERY clo...

LINQ to SQL: How to write a 'Like' select?

I've got the following SQL: select * from transaction_log where stoptime like '%2008%' How do I write this in LINQ to SQL syntax? ...

Editing Autogenerated DMBL file for WCF Service

Hi, In our project we have a standard auto-generated designer.cs file, linked to a DBML file, that contains all our object classes that map onto our database tables. We want to pass these objects directly through a WCF Service and so they need decorating with the [DataContract] and [DataMember] attributes where appropriate. What is the...

How do I modify a ReadOnly Linq property

I have a LINQ to SQL generated class with a readonly property: <Column(Name:="totalLogins", Storage:="_TotalLogins", DbType:="Int", UpdateCheck:=UpdateCheck.Never)> _ Public ReadOnly Property TotalLogins() As System.Nullable(Of Integer) Get Return Me._TotalLogins End Get End Property This prevents it from being changed e...

How to determine size in bytes of a result set from LINQ to SQL

When writing manual SQL its pretty easy to estimate the size and shape of data returned by a query. I'm increasingly finding it hard to do this with LINQ to SQL queries. Sometimes I find WAY more data than I was expecting - which can really slow down a remote client that is accessing a database directly. I'd like to be able to run a que...

Well developed web site architecture using linq to sql?

Anybody found yet a good web site architecture using linq to sql? Any help will be very helpful! ...

LINQ FormatException

I currently have an existing database and I am using the LINQtoSQL generator tool to create the classes for me. The tool is working fine for this database and there are no errors with that tool. When I run a LINQ to SQL query against the data, there is a row that has some invalid data somehow within the table and it is throwing a System....

Crystal Reports and LINQ

Has anyone figured out how to use Crystal Reports with Linq to SQL? ...

Login failed for user 'username' - System.Data.SqlClient.SqlException with LINQ in external project / class library

This might seem obvious but I've had this error when trying to use LINQ to SQL with my business logic in a separate class library project. I've created the DBML in a class library, with all my business logic and custom controls in this project. I'd referenced the class library from my web project and attempted to use it directly fro...

Attaching an ID/Label to LINQ to SQL generated code?

I'm interested in tracing database calls made by LINQ to SQL back to the .NET code that generated the call. For instance, a DBA might have a concern that a particular cached execution plan is doing poorly. If for example a DBA were to tell a developer to address the following code... exec sp_executesql N'SELECT [t0].[CustomerID] FROM [d...

LINQ to SQL insert-if-non-existent

I'd like to know if there's an easier way to insert a record if it doesn't already exist in a table. I'm still trying to build my LINQ to SQL skills. Here's what I've got, but it seems like there should be an easier way. public static TEntity InsertIfNotExists<TEntity> ( DataContext db, Table<TEntity> table, Func<TEntity,b...

Repository Pattern Implementation Experience

I am getting ready to start a new asp.net web project and I am going to LINQ-to-SQL. I have done a little bit of work getting my data layer setup using some info I found by Mike Hadlow that uses an Interface and generics to create a Repository for each table in the database. I thought this was an interesting approach at first. However...

Linq to SQL Association combo box order

This is kind of a weird question and more of an annoyance than technical brick wall. When I'm adding tables and such using the Linq-to-SQL designer and I want to create an association using the dialogs. I right click on one of the target tables and choose Add > Association as normal and I am presented with the Association Editor. The P...