linq-to-sql

How to create dynamic table in dbml file?

I'm using linq to sql. I have a table in dbml file that some of its fields can be generate dynamically (at run time). Is there any way to add fields to a table dynamiccaly , or add a class to dbml file dynamically? ...

Paging using Linq-To-Sql based on two parameters in asp.net mvc...

As two parameters i say currentPage and pagesize .....I thus far used sql server stored procedures and implemented paging like this, GO ALTER PROCEDURE [dbo].[GetMaterialsInView] -- Add the parameters for the stored procedure here @CurrentPage INT, @PageSize INT AS BEGIN -- SET NOCOUNT ON added to prevent extra result se...

get count from Iqueryable<T> in linq-to-sql?

The following code doesn't seem to get the correct count..... var materials = consRepository.FindAllMaterials().AsQueryable(); int count = materials.Count(); Is it the way to do it.... Here is my repository which fetches records... public IQueryable<MaterialsObj> FindAllMaterials() { var materials = from m in db...

Keeping Linq to SQL alive when using ViewModels (ASP.NET MVC)

I have recently started using custom ViewModels (For example, CustomerViewModel) public class CustomerViewModel { public IList<Customer> Customers{ get; set; } public int ProductId{ get; set; } public CustomerViewModel(IList<Customer> customers, int productId) { this.Customers= customers; this.Product...

How can I map stored procedure result into a custom class with linq-to-sql?

I have a stored procedure that returns a result set (4 columns x n Rows). The data is based on multiple tables within my database and provides a summary for each department within a corporate. Here is sample: usp_GetDepartmentSummary DeptName EmployeeCount Male Female HR 12 5 7 etc... ...

ASP.NET MVC <OutputCache> SqlDependency (CommandNotification?) with LINQ queries

Hello, I use LINQ queries in my ASP.NET MVC application and want to use OutputCache in some of my Actions. I hear this should be possible with CommandNotifications. But those seem to only go for self-created SQLCommands, or am I wrong? Can I manually tell SQL server to send SQLDependency notifications if certain tables change? And if...

How to avoid geometric slowdown with large Linq transactions?

I've written some really nice, funky libraries for use in LinqToSql. (Some day when I have time to think about it I might make it open source... :) ) Anyway, I'm not sure if this is related to my libraries or not, but I've discovered that when I have a large number of changed objects in one transaction, and then call DataContext.GetCha...

Linq To SQL vs Entity Framework Connection Strings

Thanks for taking a look at my post. I've been working with linq to sql and have generally been happy, until i just noticed that database table names are hardcoded into the classes/dbml files-- which can't work in our environment. We need to be able to have database names completely changeable via web.config-- in one place. That's a def...

linq to sql using foreign keys returning iqueryable(of myEntity]

I'm trying to use Linq to SQL to return an IQueryable(of Project) when using foreign key relationships. Using the below schema, I want to be able to pass in a UserId and get all the projects created for the company the user is associated with. DB tables: Projects Projid ProjCreator FK (UserId from UserInfo table) Companyid FK (Co...

Unique key violation on insert of special char string

I'm having issues when trying to insert nvarchar values in sql server with a linq-to-sql + c# program. Here is the code: public partial class Recipient { private static object _recipientLock = new object(); public static Recipient Find(string email, string displayName, MyDataContext db) { ...

Retrieving top 50 rows from Table using LINQ

Hey, Am new to LINQ, and am trying to retrieve the top 50 rows of a particular table. In SQL Server using an actual query i coudl say "Select TOP 50 from Transactions" , but not sure how i need to do that with LinQ Any pointers that could help ? Thanks ! ...

Using old-school ado but can anyone improve this using L2S or dynamic sql

I am rolling through all the cols on a particular row for processing. I am looking in general to replace using ado.net with L2S or some dynamic sql that can positionally read the columns on a particular row for processing. This is my test code. I apologize for inefficiencies like sending the DataTable down to find the col name. It is a...

How do I get LinqToSql to pass “index hints” to sql server?

As we can’t trust our customers to update the index stats etc in sql server, we have in the past had to use index hints. (As some of our customers are still on Sql Server 2000, we also can’t depend on the better query optimizer in later version of Sql Server). So how do I pass in index hints when using LinqToSql to build a query rathe...

Dynamic "WHERE IN" on IQueryable (linq to SQL)

I have a LINQ to SQL query returning rows from a table into an IQueryable object. IQueryable<MyClass> items = from table in DBContext.MyTable select new MyClass { ID = table.ID, Col1 = table.Col1, Col2 = table.Col2 } I then want to perform a SQL "WHERE ... IN ...." query on the results. This works fine using the following. (return ...

VB.NET LINQ Result Set Manipulation.

I have a table that looks like this: ID / Description / textValue / dateValue / timeValue / Type 1 / FRRSD / NULL / 2010-04-16 00:00:00.000 / NULL / classdates Now I've got a LINQ command to pull only the rows where the type is classdates from this table: Dim dbGetRegisterDates As New dcConfigDataContext Dim getDates = ...

Unit testing with Data Access Layer

Hi, what is a good way to write unit tests with a LINQ to SQL DAL? Currently I am doing some database testing and need to create helper methods that access the database, but I don't want those methods in my main repo's. So what I have is two copies of the DAL, one in my main project and one in the Test project. Is it easier to manage ...

LinqToSql - Parallel - DataContext and Parallel

In .NET 4 and multicore environment, does the linq to sql datacontext object take advantage of the new parallels if we use DataLoadOptions.LoadWith? EDIT I know linq to sql does not parallelize ordinary queries. What I want to know is when we specify DataLoadOption.LoadWith, does it use parallelization to perform the match between each...

Trouble Passing Parameter to LinqToSql Stored Procedure

public IEnumerable<T> ExecuteStoredProcedure<T>(params object[] parameters) { Type genericType = typeof(T); string commandthing = genericType.Name.Replace("Result", ""); //_db is my Linq To Sql database return _db.ExecuteQuery<T>(commandthing, parameters).AsEnumerable(); } ...

Error when calling SQL SP via LINQ

Newbie problem: I have a SQL SP with ten parameters (eight input, two output) but when I attempt to call it via LINQ from code I get the following error message: "The best overloaded method match for 'DataClassesDataContext.ST_CR_CREATE_CASE_BASIS(string, string, string, string, System.DateTime?, string, string, string, ref int?, ref in...

Linq-to-SQL Grouping not ordering correctly

Hi can someone help me convert this tsql statement into c# linq2sql? select [series] from table group by [series] order by max([date]) desc This is what i have so far - the list is not in correct order.. var x = from c in db.Table orderby c.Date descending group c by c.Series into ...