linq-to-sql

Find performance bottleneck in a method

I have a specific problem with a bottleneck in my code that I would like to iron out, but I would like to know generally, for the future, how I would go about finding quickly where a bottleneck occurs without having to re-invent the wheel. Here is my method's code but like I said, I'd like to know how to generally find out how long the ...

Does Linq to Sql have onChanging?

Hi I am looking at this tutorial yet it uses the entity framework. so I am wondering can I do the same thing with linq to sql and if so how? They seem to use this OnChaning thing but I don't know if linq to sql has it. ...

The type or namespace name 'Linq' does not exist in the namespace 'System.Data'

We're getting an error when deploying a project to one of our client's servers. The system works fine in our local dev and staging environments. The error is: The type or namespace name 'Linq' does not exist in the namespace 'System.Data' We've done the obvious checks: - We have the references in the web.config for System.Data.Linq...

Check the date with Linq-to-SQL

I have the following problem: in a database table are Sales recorded. One of the field is the SaleDate which is a SQL Server Date type. The Website now allows to search in this field. And it allows to search only for the year. Let's assume there is one record with the date 2008/11/01. If I search for "2008" the entry is returned, which ...

How to write that special select query

Hi , I have a post class : class Post { public int ID; public int? ParentID; } The only difference between answer and question in post class is that question has parend id equals null. And I want to write one query which always return question and it's answers no matter i pass to it ID of question or ID of answer for example: I h...

Advanced non-trivial linq-to-sql queries list?

I study linq for some months and i have a strange feeling that there are no hidden areas and possibility to grow as a programmer, opposing to SQL which still offers tasks which take a lot of mind effort. Could anybody advise some advanced non-trivial linq questions list - queries particularly - if such exists? ...

Which one is better lambda expressions or .....

I have following LINQ to SQL query from msg in TblUserMessages join user in Aspnet_Users on msg.FromUserID equals user.UserId select new { msg.FromUserID, msg.ToUserID, msg.MessageLocationID, msg.MessageID, user.UserName } And following lambda expression: TblUserMessages .Join ( Aspne...

Using a FormView with LINQ

Hello, I am using a FormView control to edit a record fetched using a LinqDataSource. In essence, the markup for the FormView and the data source looks like this: <asp:FormView ID="RuleInstancePropertiesFormView" runat="server" DataKeyNames="RuleInstanceId" DataSourceID="RuleInstanceDataSource" DefaultMode="Edit" Visible="false" CssCla...

C# Dynamic WHERE clause in a LINQ to SQL Query

I would like to execute a LINQ query with a dynamic where clause depending on how many different options a user has entered for their criteria. Is this possible? I have posted code below of how I would like it to work. Anyone got any suggestions? P.S. I have attempted using the .Contains method (generating a WHERE IN on SQL, however ...

Setting up linq db connection string

Hi, I created a connection using the server explorer, and dragged my entire database over (all tables) to the designer. I want linq to use my connection string in the web.config when I deploy it, how do I make it do this instead of using the connection string created in the server explorer? ...

How do I select a subset of items from an anonymous type IEnumerable?

I have the following code. MyDataContext db = MyDataContext.Create(); bc = db.BenefitCodes.Select( b => new { BenCd = b.BenCd , Description = b.BenDesc , BenInter...

Do linq2sql expressions always return iquerable?

Do linq2sql expressions always return iquerable? Can I return ILIST if I wanted? ...

How to retrieve identity ID when inserting a row in the db using linq

How to retrieve identity ID when inserting a row in the db using linq? ...

Using linq, database doesn't have FK relations to tables

Hi, I have a database that has primary key fields in its tables, but the FK mappings are not in place. What are the ramifications of this when using linq-to-sql? ...

Null Reference Exception In LINQ to SQL DataContext

I have a Null Reference Exception Caused by this code: var recentOrderers = (from p in db.CMS where p.ODR_DATE > DateTime.Today - new TimeSpan(60, 0, 0, 0) select p.SOLDNUM).Distinct(); result = (from p in db.CMS where p.ORDER_ST2 == "SH" && p.ODR_DATE > DateTime.Today - new TimeSp...

Can I extend the operators that LINQ-to-SQL supports?

If I wanted to badly enough, could I add additional LINQ constructs to LINQ-to-SQL (as I would be able to if creating my own LINQ provider)? For instance, many of the built-in LINQ operators (XYZ.Any()) get directly translated to SQL (e.g. IF EXISTS(XYZ) ). If I needed a specialized construct, would I even be able to augment the set, o...

ASP.NET MVC + LINQ exception

Hi, I've got a ASP.NET MVC application that works great for 99.9% of the time. Once in a blue moon though things go really bad and I was wondering if anybody could shed some light on what might go wrong here. The web application is using Linq2SQL and blows up in a controller after the following set of instructions: const ...

Is LINQ to SQL and Dotnetnuke is good choice or we should stick to 3 Tier architecture ?

Project Scenario Technology : Dotnetnuke (Approx. 100 - 150 screens) Data Architecture : LINQ to SQL selected with Codesmith PLINQO Modules are customized, so its fine if it does not work with Oracle or MySQL as backend So, the question is Due to selection of LINQ to SQL in place of 3-tier provider model, it will create any issue ? ...

Eager loading of Linq to SQL Entities in a self referencing table

I have 2 related Linq to SQL questions. Please see the image below to see what my Model looks like. Question 1 I am trying to figure how to eager load the User.AddedByUser field on my User class/table. This field is generated from the relationship on the User.AddedByUserId field. The table is self-referencing, and I am trying to figu...

How do I use Count and Group in a select query in Linq?

I had the following Linq code: var allRequests = model.GetAllRequests(); var unsatisifedRequests = (from request in allRequests where request.Satisfied == false select request) .OrderBy(r => r.RequestedOn) ...