Rick Strahl's Weblog
Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact
•
Articles
•
Products
•
Support
•
Advertise
Sponsored by:
West Wind
WebSurge
- Rest Client and Http Load Testing for Windows
advertise here
WebLog Posts in Category LINQ
Archives
November, 2024 (1)
October, 2024 (1)
September, 2024 (1)
August, 2024 (1)
July, 2024 (4)
June, 2024 (1)
May, 2024 (2)
April, 2024 (1)
March, 2024 (2)
February, 2024 (1)
January, 2024 (2)
December, 2023 (1)
November, 2023 (2)
Categories
ASP.NET (325)
.NET (182)
Windows (78)
JavaScript (72)
jQuery (61)
Visual Studio (54)
WPF (48)
IIS (48)
Csharp (47)
HTML (46)
AJAX (45)
ASP.NET (33)
Localization (32)
LINQ (30)
WCF (28)
MVC (26)
Personal (25)
Security (23)
HTML5 (23)
FoxPro (22)
CSS (21)
C# (20)
Angular (20)
Web Services (19)
Web Api (16)
COM (16)
ADO.NET (15)
Vista (11)
Sql Server (11)
XML (11)
WebView (10)
HTTP (10)
IIS7 (10)
Markdown (9)
Microsoft AJAX (8)
IIS7 (7)
West Wind Ajax Toolkit (7)
Web Connection (7)
NuGet (6)
Markdown Monster (6)
Entity Framework (6)
Html Help Builder (5)
Live Writer (5)
Internet Explorer (5)
C++ (5)
ASPNET5 (5)
Mobile (5)
SignalR (5)
Software Development (5)
Web (5)
OWIN (5)
WinForms (5)
Westwind.Globalization (4)
Source Control (4)
Silverlight (4)
Cordova (4)
Conferences (3)
DataBinding (3)
ASP.NET Core (3)
Help Builder (3)
ISV (3)
LetsEncrypt (3)
Networking (3)
Office (3)
Opinion (3)
Razor (3)
Web Browser Control (3)
WebLog (3)
Web Development (2)
Visual Studio Code (2)
Tools (2)
Speaking (2)
RegEx (2)
RSS (2)
Linux (2)
Installation (2)
Bugs (2)
Help (2)
Dotnet (2)
.NET Standard (2)
Addins (2)
Deployment (2)
Authentication (2)
ASP.NET vNext (2)
ADO.NET (1)
Chocolatey (1)
Blazor (1)
Blogging (1)
Desktop (1)
Control Development (1)
Credit Card Processing (1)
Cross-Platform (1)
.NET ASP.NET Windows (1)
Security (1)
Visual Studio (1)
ASP.NET IIS (1)
ASP.NET Markdown (1)
AI (1)
Angular JavaScript (1)
Dynamic Types (1)
Email (1)
CSharp Dotnet (1)
Git (1)
Graphics (1)
Hardware (1)
FireFox (1)
Flexbox (1)
IOS (1)
JSON (1)
Migration (1)
rxJs (1)
SEO (1)
RazorPages (1)
Musings (1)
Travel (1)
Typescript (1)
Testing (1)
Threading (1)
VS Code (1)
Web Deployment Projects (1)
Web Design (1)
Web Assembly (1)
WebSockets (1)
WebSurge (1)
WebBrowser (1)
WebDeploy (1)
WFH (1)
Windows-Terminal (1)
Windsurfing (1)
WPF Windows (1)
WSL (1)
wwHoverPanel (1)
LINQ to SQL and missing Many to Many EntityRefs
11 comments
December 24, 2009 - Maui, Hawaii
LINQ to SQL expects every table to be mapped to have primary keys which is reasonable. However, today I ran into a problem with an existing database and a many to many relationship which did not have a Pk in the link table. The model and underlying XML seemed to map this just fine, however, the actual generated code did not approve of this arrangement.
LINQ to SQL, Lazy Loading and Prefetching
11 comments
October 12, 2009 - Maui, Hawaii
Lazy loading in an ORM can be really useful or a royal pain if you walk through a lot of data. LINQ to SQL uses lazy loading of related entities and entity sets but there are a couple of ways that allow you to do eager loading instead. Both require some extra effort and foresight.
Fun with Func<T,TResult> Delegates, Events and Async Operations
12 comments
October 05, 2009 - Maui, Hawaii
Delegates are powerful for event handling, highly useful in LINQ and a core requirement for async operations. Func
makes using delegate based logic a lot easier by providing a generic implemenation that in many cases allows you to skip creation of a separate delegate and instead just point at the Func
definition which can be a big timesaver and a nice way to remove delegate defintions from your namespaces.
System.Data.Linq.Binary is not XmlSerializable
11 comments
July 16, 2009 - Hood River, Oregon
LINQ to SQL generates TimeStamp fields as System.Data.Linq.Binary types in the data model it creates. This type unfortunately doesn't serialize and XmlSerializer and therefore Web Services in general fail with a downright serialization failure. It's possible to work around this by using internal scope but it isn't a perfect solution.
LINQ to SQL and Transactions
20 comments
July 14, 2009 - Hood River, Oregon
Using explicit Transactions with Linq to Sql is fairly rare but when you need them you'll find that it natively doesn't provide manual transaction management. Rather you have to rely on the TransactionScope class to provide transaction wrapping. Here's a contrived example, and a couple of different transaction scenarios using TransactionScope to manage multiple L2S data operation as a single transaction.
LINQ to SQL and alternate Providers
8 comments
May 18, 2009 - Maui, Hawaii
I’ve tried an interesting experiment today trying to see if I can get LINQ to SQL to run with a custom ADO.NET Data Provider I’ve created some time ago. Basically I implemented a provider that is a proxy to a remote Web ‘service’ that can marshal SQL commands via Web Requests on a remote server. I implemented a custom provider for this interface that ships XML across the wire and marshals...
LINQ to SQL DBML fails to build or open
17 comments
October 10, 2008 - Maui, Hawaii
Arrgh. Today I got back to a LINQ to SQL app that’s been sitting idle for some time. It’s a demo app and as I started the app up and compiled the solution I got: Error 1 Build failed due to validation errors in C:\projects2008\TimeTrakker\TimeTrakkerBusiness\model\TimeTrakker.dbml. Open the file and resolve the issues in the Error List, then try rebuilding the project....
LINQPad as a Code Snippet Execution Engine
8 comments
April 17, 2008 - Redmond, Washington
LINQPad is an awesome tool to quickly execute code. Besides the obvious LINQ testing features that its name implies, LINQPad also can come in quite handy as a generic .NET code snippet execution utility that allows you to run any .NET expression or single statement block. It's a great tool for your toolbox to quickly check behavior of BCL functions for example...
Dynamic Queries and LINQ Expressions
19 comments
April 14, 2008 - Portland, Oregon
Using LINQ to SQL in some scenarios where dynamic expresions are required on the right side of a LINQ query expression can be tricky. How do you for example allow a query to use a dynamic field in a query and then query its data? Due to the strong typed nature of LINQ direct LINQ syntax can't be used for this sort of query, but there are a several ways to work around this by using dynamic expressions.
LINQ to SQL ObjectTrackingEnabled and Deferred Loading of Related Data
6 comments
April 12, 2008 - Maui, Hawaii
LINQ to SQL supports object tracking by default, but if running queries it's often more efficient to turn off object tracking. This can be done with ObjectTrackingEnabled, but unfortunately this option has a rather severe side effect on deferred object loading.
LINQifying - getting rid of CollectionBase?
10 comments
March 26, 2008 - Maui, Hawaii
If you're sitting on some old types that implement CollectionBase you might find that they don't directly work with LINQ. Here's how you can make these types work with LINQ.
Update to LINQ to SQL Business Object Wrapper Sample
11 comments
February 05, 2008 - Maui, Hawaii
Last night I after I posted the LINQ DataContext post I realized that I hadn't ever updated the LINQ Business Object Layer example app for .NET 3.5 RTM. Although I've long updated the code, since I use it here in a few internal applications as a base business object wrapper around LINQ to SQL, I...
Linq to SQL DataContext Lifetime Management
90 comments
February 05, 2008 - Maui, Hawaii
The DataContext is the central object that holds LINQ to SQL together. This post talks about a few different approaches you can use to hang on to your DataContext in the course of a request, to pass between layers or to manage on a per thread/request level.
LINQ To SQL and the Web.Config ConnectionString Value
29 comments
December 07, 2007 - Maui, Hawaii
I just got had by an odd behavior in the LINQ to SQL model designer when working with a LINQ to SQL Model in a separate class library project. I use LINQ to SQL in a business layer which always lives in a separate assembly and so the model does not live in the same project as the Web (or other)...
Anonymous Types in C# 3.0
12 comments
November 15, 2007 - Maui, Hawaii
One of the most convenient features of C# 3.0 is the ability to create new types 'on the fly' using Anonymous Types. Anonymous Types are essentially compiler generated types that you don't explicitly declare with an official type declaration. Rather you define the type inline as part of the code...
Type Intializers in C# 3.0
8 comments
November 12, 2007 - Maui, Hawaii
During my LINQ to SQL session at DevConnections somebody in the audience asked what happens behind the scenes when you use type initializers in C# 3.0 and well it turns out I gave a hedged answer with a guess that was - uhm - wrong. So here's a discussion of how this feature actually works....
Complex Detached Entities in LINQ to SQL - more Nightmares
38 comments
October 01, 2007 - Hood River, Oregon
Ok, so I thought I had the detached entity state in LINQ to SQL figured out, only to have that thrown back into my face. The word from Microsoft is that if you have an entity that was loaded through a LINQ to SQL DataContext at any point it cannot be re-attached to the DataContext.
A simple Business Object wrapper for LINQ to SQL
61 comments
September 27, 2007 - Hood River, Oregon
I've been talking about how I'm using a small business object wrapper around LINQ to SQL to provide better abstraction of the LINQ to SQL functionality and I suppose the time's come to be bit more specific. This is going to be a long post with a fair bit of code and a brief discussion of the whys and hows...
LINQ to SQL Queries out of a Business Layer
23 comments
September 26, 2007 - Hood River, Oregon
Using LINQ to SQL for queries out of a business layer has some cool benefits in that core business layer queries returned from business objects can further refine query before the final query operates against the database. This allows the client to perform common formatting like picking which fields to retrieve, changing order or applying a final front end filter on the data. It also allows the client to choose best to represent the query results as an entity list or data reader/data table etc. This entry shows a few ways of how this has advantages and how a business object can greatly facilitate the data serving process.
LINQ to SQL Serialization bites me again
5 comments
September 21, 2007 - Hood River, Oregon
I'm mucking around with a bit of code today that's using AJAX and returning some data from my business layer that's using LINQ to SQL Entities. I mentioned some time that one issue that I ran into and continue to bump my head against is that LINQ to SQL has big issues serializing its entities. The...
First Impressions on LINQ to SQL
14 comments
September 11, 2007 - Hood River, Oregon
I've been experimenting with LINQ to SQL for the last few weeks and there's a lot to like as well as a few things to think about. In this editorial I'll describe some of the things that worked well and some of the issues I struggled with and how I worked around them.
LINQ to SQL and Serialization
32 comments
September 02, 2007 - Hood River, Oregon
LINQ to SQL provides entity objects that can be used easily for object access to data members. But these objects can be difficult to deal with if you need to serialize them in Web Services or in other ways because relationships are often circular. Here's a discussion of things to watch out for and how you can get around the issues.
Version Fields and LINQ: Careful of underscores in Field Name
1 comment
August 28, 2007 - Hood River, Oregon
This probably falls into the bonehead category, but this might bite somebody else so I'm writing it up: LINQ to SQL works best when your database tables have version fields that can be used to see change state. So recluctantly I resigned myself to give in to this and decided I'd use a consistent...
Dynamic Expressions in Linq to Sql
14 comments
August 28, 2007 - Hood River, Oregon
Using LINQ there are two issues that I've been struggling with and both have to do with dynamic query results: Hitting the wall with SQL that can't be expressed via LINQ and using dynamic expressions inside of LINQ queries from within framework level code. As it turns out there are ways that this can be addressed with lower level LINQ methods that provide the abillty to be a bit more flexible in controlling what SQL gets executed and creating dynamic expressions for results.
LINQ To Sql - Getting a Command Object from a Query
20 comments
August 24, 2007 - Hood River, Oregon
LINQ to SQL is all about returning object from database queries, but sometimes it's actually useful to use good old DataReaders or DataTables - especially in ASP.NET applications that use DataBinding. Entities are objects and databinding requires Reflection which is very slow, compared to a DataReader. Luckily LINQ to SQL provides the abillity to retrieve a Sql Command object that can be used to return an alternate result set.
Multiple Enumeration of LINQ results
7 comments
August 16, 2007 - Hood River, Oregon
LINQ result set enumeration can be a little unexpected if you don't pay close attention the returned Enumeration. Because of the way queries are enumerated at enumeration time, not when they are declared can easily result in multiple queries being run against the LINQ data or list source.
LINQ to SQL and Disconnected Entities Follow-up
49 comments
August 15, 2007 - Hood River, Oregon
Several people have been flogging me for my LINQ and disconnected Entity post, so I thought I should follow up on the issues I've been having. First let me restate Entity issue I raised a couple of days ago, but let me present it in a simpler context with the Northwind database, so you can try...
LINQ to SQL and Dynamic Queries and Expressions?
24 comments
August 13, 2007 - Hood River, Oregon
Continuing my experiments with LINQ in the middle tier I ran into another problem: Inability to make LINQ run any dynamic operations that are not defined explicitly in the LINQ to SQL import. For building a generic business framework that doesn't have concrete type references (to say a PK field) but dynamically needs to create SQL to query data. Even relatively simple things like retrieve a single record by primary key where primary key is dynamic not explicit is not easily accomplished without getting real low level into Lambda expression creation.
LINQ to SQL and attaching Entities
45 comments
August 12, 2007 - Hood River, Oregon
I have been experimenting with LINQ to SQL in the middle tier and have run into the apparently common issue of re-attaching entities to a DataContext in cross tier scenarios. Either the support re-attachment is not there or it is broken but either way it doesn't work which makes it pretty tough to use LINQ to SQL in the middle tier.
LINQ and dynamic Query Results?
31 comments
March 22, 2007 - Maui, Hawaii
I've been mostly watching LINQ take shape and only recently started in looking at it a bit more closely.I've been pretty excited about the prospect of LINQ in general and the database connectivity in particular - after all I come from an XBase background where a built in Data Definition Language...