linq-to-sql

simple linq to sql has no supported translation to SQL.

i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from p in db.Posts let categories = GetCategoriesByPostId(p.PostId) let comments = GetCommentsByPostId(p.PostId) select new Subnus.MVC.Data.Model.Post ...

Linq insert with no primary key

I need to insert records into a table that has no primary key using LINQ to SQL. The table is poorly designed; I have NO control over the table structure. The table is comprised of a few varchar fields, a text field, and a timestamp. It is used as an audit trail for other entities. What is the best way to accomplish the inserts? Cou...

Do you ToList()?

Do you have a default type that you prefer to use in your dealings with the results of LINQ queries? By default LINQ will return an IEnumerable<> or maybe an IOrderedEnumerable<>. We have found that a List<> is generally more useful to us, so have adopted a habit of ToList()ing our queries most of the time, and certainly using List<> in...

Linqtosql remove from list

myRule.ToList().RemoveRange(0, count); Even though it does not give me error, it does not work. What's the other way? ...

Linq to SQL: How do I stop the auto generated object name from being renamed?

In visual studio 2008, when I drag a database table into my dbml screen, any tables that end with the letter s automatcially get the s removed from the dbml object. Is there any way to disable this? Also, the collection of rows also gets an s appended to the collection property name. Is there a way to change that as well? Thanks ...

LINQ to SQL: Multiple / Single .dbml per project?

I've read Rick Strahl's article on Linq to SQL DataContext Lifetime Management hoping to find some answers on how I would manage my .dbml files since they are so closely related to DataContext. Unfortunately, Rick's article seems to be focused on DataContext lifetime at runtime though, and my question is concerned with how the .dbml's s...

sql server 2008 table valued parameters linq2sql

Has anybody experimented with these. Is this supported? ...

LINQ To Entities and Lazy Loading

In a controversial blog post today, Hackification pontificates on what appears to be a bug in the new LINQ To Entities framework: Suppose I search for a customer: var alice = data.Customers.First( c => c.Name == "Alice" ); Fine, that works nicely. Now let’s see if I can find one of her orders: var order = ( from o in alic...

ASP.NET Data Access Layer. Is using sqlhelper.cs bad?

I'm about to start a new .net web project. Previsouly for my n-layer web apps i've used the "Microsoft Data Access Application Block" (sqlhelper.cs) for the data access, then an interface class to interface with the object classes. I'm aware this technique is a bit dated and was looking to use something a little more with the times. I'...

Why and When to use LINQ ?

i have never used LINQ in any of my projects , i have always used ado.net /OR tool in my Business App projects , so i want to know What are the benefits of LINQ ? why and when anybody should use LINQ ? ...

linq2sql disadvantages

Hi. I am hearing a lot of rumours that Linq2Sql is not going to be supported any more in the next version of .net. I like Linq2Sql a lot and find it very easy / lightweight to work with. I can understand some of the problems people have had with it (ppl used to nhibernate...) but used correctly I think most problems can be solved. I curr...

Dynamic Paramter Count for SQL with C#

So I was thinking about creating a dynamic sql question, meaning that i want the amount of parameters to be dynamic. Having looked at this: http://stackoverflow.com/questions/337704/parameterizing-a-sql-in-clause#337725 i was thinking that using like '%x%' is SLOW and not good. What i actually would like to do is using the IN keyword a...

LINQ: Max or Default?

What is the best way to get the Max value from a LINQ query that may return no rows? If I just do Dim x = (From y In context.MyTable _ Where y.MyField = value _ Select y.MyCounter).Max I get an error when the query returns no rows. I could do Dim x = (From y In context.MyTable _ Where y.MyField = value _ ...

Linq2Sql cannot orderby anonymous type?

Hi folks, I have some SQL that does an order by case statement. It works fine. I can't replicate it as Linq2Sql. Here's a quick hacked up version of the SQL i made, simplified and really dumbed down. Please ignore what the sql is trying to do (business logic wise) as i made this up, for the question. SELECT u.Id, u.Name ...

Linq to Sql query using "not in"

Can linq to sql query using not in? e.g., SELECT au_lname, state FROM authors WHERE state NOT IN ('CA', 'IN', 'MD') ...

How to retrieve Stored Procedure schema using Linq to SQL?

Basically I am trying to retrieve a list of stored procedure parameters using Linq to SQL? Is there a way to do this? ...

Problem refreshing tables in the LINQ to SQL designer

I have been using LINQ to SQL for a while, and there is one thing that has always bothered me. Whenever I modify the schema of a table, in order to refresh it in the designer, I have to delete it and then add it back. That's fine, but this means I have to actually find the table in the designer. I have about 100+ tables in my database,...

linq to sql: join multiple columns from the same table

How do I inner join multiple columns from the same tables via Linq? For example: I already have this... join c in db.table2 on table2.ID equals table1.ID I need to add this... join d in db.table2 on table2.Country equals table1.Country ...

LINQ DBML isn't letting me insert, update, delete or select data from any tables? Why?

I've created a DBML file for a LINQ to SQL mapping and after dragging all of my tables into the designer surface. In the properties of each table, the "Delete", "Insert" and "Update" are grayed out so they're not editable like they're disabled. I'm not sure why this is. Does anyone know how to make it so that I can insert, update and del...

How to do Joins in Linq using lambdas and the expression tree?

I'm trying to do a JOIN in Linq using lambda expressions ... and running into some problems. I have two entities, Comments and CommentSources. CommentSources are associated to Comments. I have the following code, which does work: 01 IQueryable<Data.Comment> query = ctx.DataContext.Comments; 02 03 04 if (criteria.IsDeleted == Delete...