linq-to-sql

Loading Complete graph from Sql using LINQ

Assume we have a Menu class that has SubMenus (which is the same type of Menu therefore can have SubMenus and Items too) and Items (which has a different type) and we stored them in two tables(One for Menus and one for Items). Is there any way to load complete graph of the Menu class (all of its SubMenus and Items) using LINQ to SQL? ...

Databinding expression for retrieving value of related collection using LINQ

I have a GridView that is bound to a LINQDataSource control that is returning a collection of customers. Within my DataGrid I need to display the home phone number of a customer, if they have one. The phone numbers of a customer are stored in a separate table with a foreign key pointing to the customer table. The following binding exp...

Linq to SQL: DISTINCT with Anonymous Types

Given this code: dgIPs.DataSource = from act in Master.dc.Activities where act.Session.UID == Master.u.ID select new { Address = act.Session.IP.Address, Domain = act.Session.IP.Domain, FirstAccess = act.Session.IP.FirstAccess, LastAccess = act.Session.IP.LastAccess, IsSpider = act.Session.I...

Renaming LINQ 2 SQL Entity Properties Through Partial Classes

Hi, Can I use partial classes to create properties that points to an association property generated by the L2S designer. Also, will I be able to use the new property in queries? How can I achieve this? ...

How do I use LINQ on a store procedure with a Select Statment?

Hi there, How do I use LINQ on a store procedure with a Select Statment? I know how can I use store procedure to execute some procedure for me, however, if I want to return some data from a store procedure? How do I do that? Regards ...

How Do I Edit Database Records In A DataGridView Using LINQ to SQL?

I'm so close on this one, but I need a little help. I have a simple WinForms app that uses LINQ to SQL to grab data that needs to be reviewed from a database and stuff it into a DataGridView. That part works great, but the connection I can't seem to make is how to get the data back into the database when things change. Here's what I h...

Transaction timeout expired while using Linq2Sql DataContext.SubmitChanges()

Hi guys, please help me resolve this problem: There is an ambient MSMQ transaction. I'm trying to use new transaction for logging, but get next error while attempt to submit changes - "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." Here is code: public static void Sav...

Linq to SQL - Update a calculated field (like "subtotal") on parent object when child objects change

Hello, I have a L2S SalesOrder entity with a child set of LineItems. Using winforms, on my Sales Order form I have a datagridview bound to the LineItems and it works like a dream. If the user changes a LineItem quantity (for instance), my LineItem partial class handles the OnQuantityChanged and recalculates the LineItem SubTotal field a...

convert sql to linq help please

select m.messageID,m.[addeddate],m.message,count(*) as Comments from intranet.dbo.Blog_Messages AS m inner join intranet.dbo.Blog_Comments AS c on c.messageid = m.messageid group by m.messageID,m.[addeddate],m.message need help converting this to linq to sql ...

Change Select statements generated for generating gridview in Dynamic Data???

I am using ASP.net Dynamic Data scaffolding. I realize that for a table like table1: EducationLevel (id,levelname,modby,modon) table2: Course(id,coursename,modby,modon,belongsToEduLevel) where belongsToEduLevel is the FK. In this case dynamic data never shows levelname in the grid instead, it shows Operations | Modon | EducationProgr...

In explicit LINQ-to-SQL (C#) does order matter?

Hi, I know Linq-to-SQL is dead, but anyway, I think this is really basic, I'm just confused about what magic Linq-to-SQL does and doesn't do with regards to the SQL it generates. If I have built up an Expression tree as "myPredicate", and have something like this: (from request in DataContext.RequestsTable select request).Where(myPredi...

ASP.NET MVC, jQuery/AJAX cascading dropdownlist issues with LINQ2SQL??

Hi guys, The premise: Get a dropdownlist's content based on the value selected in the first one. Literal data returns successfully. LINQ queries on a LINQ2SQL Datacontext fail. Being a total rookie at this MVC/LINQ/jQuery stuff, I battled for HOURS on end trying to figure out what was wrong w/ my understanding of the code. When i hard...

Turn very simple Expression<Func<T, bool>> into SQL where clause

I have a number of different data sources that I need to query and have been able to do confine all my queries to very simple expressions with no more than 2 conditions. An example of typical complexity of my lamba Expressions is: b => b.user == "joe" && b.domain == "bloggs.com" On my non-SQL data sources I'm ok as I can convert them ...

LINQ To SQL Class diagram in Visual Studio

Is there a way to copy the class diagram generated by the LINQ To SQL ORM in VS2008 without using print screen (yes, I know it's pathetic)? For example, when I create database projects in Visual Studio I can copy the database diagrams and save them later in Paint.NET in any image format. Any idea or suggestion will be greatly appreciate...

Linq-to-SQL Table Coalesce

Let's say I have three tables: User ID | Name =========== 1 | UserA ----------- 2 | UserB ----------- Setting ID | Name | Default ========================= 1 | SettingA | ADefault ------------------------- 2 | SettingB | BDefault ------------------------- And UserSetting UserID | SettingID | Value ====================...

Linq2sql Find Top Subscribers Question

Hello all, It has been a while since I have wrote any code due to military obligations (Afghanistan, Reserves) and I have a question with regard to linq 2 sql (hell, I would do this as a stored proc at this point...I really am rusty). I have a table of feed names, and those feeds have subscribers in another table (foreign key associatio...

How to check for LINQ to SQL connection error

How to check if Linq.DataContext object is filled with data and no connection error has appeared? Thanks. ...

Column.DbType affecting runtime behavior

Hi According to the MSDN docs, the DbType property/attribute of a Column type/element is only used for database creation. Yet, today, when trying to submit data to an IMAGE column on a SQLCE database (not sure if only on CE), I got an exception of 'Data truncated to 8000 bytes'. This was due to the DbType still being defined as VARBINA...

Basic LinqToSql question: Why won't this compile?

I've been introducing myself to LinqToSQL lately through a poorly-made project at work. I'm curious as to why this works: var territories = db.Territories.Where(t => t.PendingUserCount > 0); But this results in a compilation error: var territories = db.Territories; if (someCondition) territories = territories.Where(t => t.Pendin...

LINQ to SQL - No Add method available

I have created a LINQ to SQL datacontext with a single datatable in it. I am trying to simply insert a new record into that table. The problem I am coming across is LINQ is not offering an Add method to pass in the new record to. I have seen countless examples where there is an Add method, but I can't seem to get it. Am I completely ...