linq-to-sql

Cassini exceptions on medium trust ASP.NET MVC application using Linq-to-SQL

I am receiving the following exception trying to browse a medium trust ASP.NET MVC application (using Linq-to-SQL) on Cassini 3.5.0.2: Could not load file or assembly 'Cassini, Version=3.5.0.2, Culture=neutral, PublicKeyToken=da0fefd60d522a7d' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x...

Linq to sql causing foreign key constraint errors

Here is the revelant code. TournamentTeam newTeam = new TournamentTeam(); TournamentTeams.InsertOnSubmit(newTeam); SubmitChanges(); TournamentParticipant newSignup = new TournamentParticipant { CheckedIn = false, TournamentID = tournamentId, UserID = participant...

LINQ to SQL debug variables

I'm building up a query using LINQ to SQL and C# and when I inspect the final T-SQL that is built the where clause looks like this: WHERE ([t0].[T_SUBJECT] LIKE @p0) AND ([t0].[T_SUBJECT] LIKE @p1) The structure of the T-SQL looks correct and I can test it using SQL Server Management Studio (SSMS) but in the code it's not working. I'd...

NOLOCK with Linq to SQL

Is it possible to get Linq2Sql to emit a NOLOCK in its SQL? And if so, how? Kind regards Scott ...

How to get the last inserted id in a Linq To Sql custom sql expression ?

Hello, Here is my problem. I'd like to get the last inserted Id with a custom sql expression in Linq To Sql. My insert method: public int Add(string Label) { _dbContext.ExecuteCommand("INSERT INTO Products (Label) VALUES (@Label);", Label); _dbContext.SubmitChanges(); var lastId = _dbContext.ExecuteQuery<int>("SELECT Sco...

Can I combine fields via Linq to Sql

I'm new to Linq to Sql, what I would like to achieve is to create a single read only property on the Entity class that is a combination of multiple fields, specifically I want to create a name field that combines- title, forename and surname. I can see how to do it by changing the .designer.cs file but know I'm not supposed to touch tha...

Linq2SQL question

Hello, I'm using LinqToSQL, creating my entities with the designer in studio which nicely creates the designer class with all corresponding entity-classes. Normally when I wanted some custom stuff added to my entities, I would create a partial class and do the custom stuff there. Here's my problem; the new ASP.NET MVC 2 (preview) contain...

LINQ to SQL - Struggling with query

I have a table with server names and logins. I need to retrieve the logins that are common across a group of servers. Given the following data: ServerName Login ------------------------------- Server1 User1 Server2 User1 Server2 User2 I would pass in Server1,Server2 and get back only User1 as User2 is not associ...

Loading Subrecords in the Repository Pattern

Using LINQ TO SQL as the underpinning of a Repository-based solution. My implementation is as follows: IRepository FindAll FindByID Insert Update Delete Then I have extension methods that are used to query the results as such: WhereSomethingEqualsTrue() ... My question is as follows: My Users repository has N roles. Do I create...

Linq to Sql - Only select certain information (w/ Predicate Builder)

I am using Linq to Sql with Predicate Builder and am trying to optimize how much information is retrieved from the database. I would like to select only certain fields to display them in a gridview. When I select only what I want, the search parameters I add (see below) don't work, and neither does PredicateBuilder. Here's what I'm cu...

Do I need to SubmitChanges after executing a stored procedure with Linq-To-Sql?

Linq-To-Sql enables calling SPs. If this SP executes an update/delete/insert, do I need to SubmitChanges() after it? ...

LinqToSQL and inheritance mapping

Hello I've been googling around on L2S inheritance, and I think I have a fair idea of the limitations/what I have to do, but just looking for some confirmation from the community. I have a REAL BASIC setup here: public abstract class BusinessObject { public int Id { get; set; } } [Table] public class Customer: BusinessObject { } ...

Automatically Compile Linq Queries

We've found that compiling our Linq queries is much, much faster than them having to compile each time, so we would like to start using compiled queries. The problem is that it makes code harder to read, because the actual syntax of the query is off in some other file, away from where it's being used. It occurred to me that it might be ...

Is it bad practice to make multiple, separate database calls from ASP.NET MVC web app?

I have a controller attribute called [RequiresCompletedProfile], that I can put on action methods to disallow a user from going there unless they have completed their profile. This was working fine when I had one kind of user, but the app has since evolved into having 2 kinds of users: Vendors and Clients. So, there is no longer a "Use...

How to bind the Command Timeout to an dbml (Linq-To-Sql data class)?

I know that we cannot set the Command Timeout in the Connection String. So I put it in the MyDataContext constructor. But there are many constructors, this file is usually overwritten by the visual designer and it doesn't seems the right way to do that. How would you do that? ...

"Callbacks" in Linq-to-SQL/ASP.NET MVC

After using .NET for several years, I've spent the last few months in the far off land of Ruby on Rails. While I can clearly see where much of Microsoft's MVC framework got it's influence, one of the things that I find myself suddenly missing when development in .NET are the Rails Model callbacks. Specifically, you can add a callback t...

Subqueries in linq

Hello, I've been trying for a couple of days to write to "translate" this query in LINQ with no success so far. Could you guys please help me? I would also appreciate some explanation to learn actually something out of it. Here is the T-SQL query: SELECT R.ResourceID, R.DefaultValue FROM Resources as R JOIN (SELECT [t0].[NameResou...

Linq to sql - Define inheritancemapping on derived class

I'm building a core engine for my blog and would like to be able to extend it very easily. At the moment my code looks like this: [Table(Name = "dbo.ContentItem")] [InheritanceMapping(Code = "MyNameSpace.Items.SysRoot", Type = typeof(SysRoot), IsDefault = true)] [InheritanceMapping(Code = "MyNameSpace.Items.SysRecycleBin", Type = typeof...

How to add day to date in Linq to SQL

I am writing this code. Here dt is input into the function, as well as someint. The column Exp is a T-SQL date column, which comes as a DateTime through Linq. return (from a in dataContext.TableOfA where a.name == "Test" && a.Exp.Value.AddDays(Convert.ToDouble(Someint)) >= new DateTimeOffset(dt) select a).First(); ...

Help me choose between linq to sql and nhibernate based on the following

Hi, Struggling between choosing linq2sql and nhibernate. Let me give you some insight in the application in point form: this is a asp.net mvc application it will have lots of tables, maybe 50-60 (sql server 2008) i would want all the basic crud logic done for me (which I think nhiberate + repository pattern can give me) i don't have ...