linq-to-sql

LINQ 2 SQL Method for all tables

My Title may be slightly off but here is what I am trying to do. I have a L2S Method that would be for every table that I would like to write once. This is to set a soft lock column where I will also need a Read and UnLock method. Here is what I have so far: public static void LockRow(string TableName, int TablePrimaryKey) { ...

LINQTOSql Missing parameter question

I have a long LinqtoSQl query in which several parameters I'm not forcing the user to specify anything. I started using a Select Case statement that would test rather or not a parameter string's length > 0 or if it's an int > 0. But I realized that I would have to test for each possibility and create queries based on each. I did some se...

LINQ to SQL Query for Many-to-Many relationship

I am moving an old ASP.net (C#) application from plain SQL queries to LINQ to SQL and am having some trouble with some of the more complex queries. In this case, I am trying to get a list of employees who have a certain set of skills. The user picks the skills to search for and the id's are supplied to the method that does the work. In t...

Very Slow problem in Web Application which use LINQ to SQL

I am developing sample web application which use C#, and LINQ to SQL. The application is very very slow and it takes about 2 secs to navigate between pages. I have already used SQL Profiler and monitor the calls to the SQL server. All SQLs looks normal to me and their execution time is always about 1 or 2 millisecs. I tried the same ...

Can't save changes to child tables using LINQ to SQL that have foreign key constraints

I am trying to teach myself LINQ to SQL and have decided to do a small MVC.NET project to get my feet wet. The problem is that I have fallen very early on with the following error. I am making a golf application so I have setup the database and got my dbml classes made. The database has a course table and a hole table. The hole table re...

Is there a per-property deferred loading option in Linq-to-Entities as there was in Linq-to-Sql

First I want to pre-thank anyone who helps with this. Back when I was programming in Linq-to-Sql there was a per-property option for deferred loading which was perfect for excluding large binary fields in a table without actually having to write special select statements to exclude each one. I can re-architect the database to make the b...

Attach: Cannot add an entity with a key that is already in use

I found a bunch of possible duplicates around this but none really seemed to be having the same problem I'm having. I'm getting a DuplicateKeyException: Cannot add an entity with a key that is already in use. Here's my SqlProductsRepository: public class SqlProductsRepository : IProductsRepository { private Table<Product> productsT...

Method 'Boolean Contains..' has no supported translation to SQL.

i have this in my query: var results = (from urls in _context.Urls join documents in _context.Documents on urls.UrlId equals documents.DocumentId let words = (from words in _context.Words join hits in _context.Hits on words.WordId equals hits.WordId wh...

Simple rating algorithm to sorting results according to user query

Hi, I'm developing a very basic web search engine that has several parts. After retrieving results according to a user query, I want to calculate rate of each result and then sort results by calculated rate. Here is my query: var tmpQuery = (from urls in _context.Urls join documents in _context.Documents ...

Linq to SQL - What am i missing?

I'm a complete newbie to LINQ, so please bare with my stupid questions. Using Visual Studio I've created a DBML file, and added a table to it from a local database. This created a data context called UserDataContext. In my ASPX page I can create an instance of the data context using: UserDataContext db1 = new UserDataContext(); Howev...

SQL Metal for specific tables or another way to refresh/add table to .dbml file

Hi, anybody have any easy way of doing this in Visual Studio, without having to use the Server Explorer ? I tried also looking at macro's but recording only produce Sub TemporaryMacro() End Sub So no luck there. Any way to script this? ...

linqtosql datacontext not holding most up to date values

Hi all, I am using c# \ .net 3.5 and linqtosql (over an sql server dbms of course). I am using my data context for automic operations. I have a GetReadonly method of a factory method that returns me a new datacontext for each atomic operation. I am able to perform CRUD operations well, though the following error occurs: When I update ...

In Linq, how to find if a set contains an element without using Count(predicate)?

Hi, Since IEnumerable.Contains() method does not accept a predicate as an argument, Most people use the following code to check the existence of something matching a condition: // ProductId is unique. if (Products.Count(c => c.ProductId = 1234) == 1) { // Products list contains product 1234. } This code forces to walk through eve...

How to create this SQL constraint.

The situation I am in is that I have a set of existing tables with incrementing Integers as Ids. I have now added a GUID to each table to be the new PK. I have a primary table dbo.ParentTable(GUID - PK, ParentTableId INT, Name VARHCHAR) and a child table dbo.ChildTable(GUID - PK, ParentTableId INT, other fields.....) and want ...

How to configure Ninject for ASP.NET MVC using LinqToSQL and Repository Pattern

I have done some searching around but have not been able to figure out how to bind LinqToSql data context's with specified connection strings into different repositories. This binding is performed in global.ajax when routes are registered. I'm using a fairly standard repository pattern to decouple the LinqToSql infrastructure from my ap...

LINQ to SQL using dynamic tables

I am developing application VS 2008, .NET 3.5 and I am trying to use LINQ To SQL. I drag & drop tables on the designer to generate the .dbml file. The problem I have that I have some dynamic tables for search indexing. I know the structure of table, only the application creates new tables like this: Files_1_1, Files_1_2, ... Files_m_...

does IQueryable<T> only get returned from the Linq to Sql or Linq to Entities classes?

In the book I'm reading "Pro Linq in C# 2010" (APress, Freeman and Ratz) the author states that IQueryable will only be returned from the classes in the Linq to Sql namespace, not in the general Linq namespace. I was surprised by this, since I thought anything that had a Where on the end had to be IQueryable. Turns out I was wrong, Where...

Is it possible to return multiple result sets using ExecuteQuery in Linq to Sql?

I know that you can return multiple results from a stored procedure and through the method generated by the designer. However, I'm trying to do the same using ExecuteQuery but it doesn't seem like it's possible. Has anyone tried or know whether this is possible? Basically I'm trying to run an ad-hoc stored procedure. By ad-hoc, I mean...

How to read large XML RAW from Linq to SQL?

I'm pretty new to Linq to SQL & Linq to XML but have cobbled together some code together that put the XML results from a stored proc into an XElement. However, it's started failing, apparently now that the XML data is getting larger (2K+) and my .Parse is reading truncated XML (the XML data comes back in two rows). Before i start fumblin...

Basic LINQ to SQL Question: How to update table class references?

I am new to LINQ. I am using Visual Studio 2008 and have created a "LINQ to SQL Classes" (.dbml) file in my project. I've added each of my database tables to the design view and everything works fine. My question is this: When a change to a table's design has been made in the database, i.e. fields added, how do you update the class...