Archives
-
Entity Framework and LINQ to Entities (4) Query Methods
This part discusses how to query SQL database with the defined mapping classes. Entity Framework and LINQ to Entities supports most of the extension methods provided by Queryable class:
-
Debugging Classic ASP with Modern Visual Studio
Recently I tried to show my Mom some websites I built when I was a kid. Those ASP code, some in VBScript while some in JavaScript, are more than 10 years old. They were running fine in PWS, but now they didn’t run in IIS 8.5. I have no idea what’s the problem. It seems a little debugging has to be done.
-
Shrink Virtual Hard Disk Image (VHD and VHDX) Files
Virtual hard disk image files (VHD and VHDX files) grow bigger during the usage. For instance, this is a 20G virtual disk file for a Windows XP virtual machine:
-
Paste code from Visual Studio 2015 to Windows Live Writer
Now it is close to the end of 2015, but Windows Live Writer 2012 is still the best Windows blogging tool. For years I use a Windows Live Writer plugin called VSPaste for code snippets. With VSPaste, any code in any language can be copied from Visual Studio, and paste into Windows Live Writer with 100% accurate syntax highlighting.
However, VSPaste has a problem with Visual Studio 2015 RTM (not with RC) – the pasted HTML code always has a white background: <span style=”background: white;”>code</span>. To quickly fix this, the easiest way is to decompile the source code of VSPaste.
VSPaste is a small dll located in Windows Live Writer’s plugin directory: C:\Program Files (x86)\Windows Live\Writer\Plugins\VSPaste.dll. It can be decompiled to a project with source code, by .NET reflector free trial version:
-
Download Liked Posts from Tumblr.com
After using tumblr.com for years, a lot of posts have been liked. It would be easier to look up if the contents of these posts are stored to local. Fortunately, tumblr has provided a set of APIs to make this easy, and even an API console to play with these APIs. The API client is also provided in:
-
Query Operating System Processes in C#
.NET framework provides some process APIs in System.Diagnostics.Process class. Only some basic information of process can be queried with these APIs. .NET does not have APIS for other information, for example, a process’s parent process/child processes. There are some options to query process informations, like performance counter, P/Invoke, etc. Querying Win32_Process class of WMI could be an easier way.
-
C# 6.0 Exception Filter and when Keyword
C# 6.0 introduces a new feature exception filter and a new keyword when. Many C# features/keywords are syntactic sugars, but exception filter/when keyword is not.
-
Configure Git for Visual Studio 2015
After installing Git, the initial Git configurations can be viewed with git config –list:
-
Batch Processing Compression Archives with Different Formats (RAR, ISO, 7z, Zip, …) in C#
Recently I need to batch process some compressed files in several hard disk drives - Some RAR/ISO/7z files need to unified to zip format; And some compression archives has to be extracted; etc..
-
Entity Framework and LINQ to Entities (6) Deferred Execution, Laziness Loading and Eager Loading
In LINQ to Objects, query methods returning IEnumerable<T> implements deferred execution. Similarly, in LINQ to Entities, query methods returning IQueryable<T> implements deferred execution too.
-
Convert HTML to Well-Formatted Microsoft Word Document
Recently I wanted to convert my LINQ via C# tutorial into a Word document (.doc). The tasks are:
-
Entity Framework and LINQ to Entities (3) Logging
As fore mentioned, this tutorial will use SQL Profiler to trace the remote SQL queries, which are translated from the LINQ to Entities queries. This is most close the the truth, because the tracing uncovers the actual SQL query executed in SQL database. Entity Framework also provides several options to log the translated SQL database operations programmatically.
-
Use Fiddler with Node.js
Fiddler is an useful HTTP proxy debugger on Windows. It would be nice if it can work with Node.js applications. To do this, just need to proxy Node.js requests through Fiddler. The default proxy is 127.0.0.1:8888. This can be viewed in Fiddler Tools –> WInINET Options –> LAN settings –> Advanced:
-
Entity Framework and LINQ to Entities (5) Query Translation
The previous part discussed what SQL queries are the LINQ to Entities queries translated to. This part discusses how the LINQ to Entities queries are translated to SQL queries. As fore mentioned, IQueryable<T> query methods work with expression trees. Internally, these methods build expression trees too, then these expression trees are translated. In Entity Framework, .NET expression tree is not directly translated to SQL query. As mentioned at the beginning of this chapter, Entity Framework implements a provider model to work with different kinds of databases like Oracle, MySQL, PostgreSQL, etc., and different database system can have different query languages. So Entity Framework breaks the translation into 2 parts:
-
Entity Framework and LINQ to Entities (2) Object-Relational Mapping
.NET and SQL database and have 2 different data type systems. For example:
-
Entity Framework and LINQ to Entities (10) Performance
The previous parts has discussed a few aspects that can impact the performance of Entity Framework and LINQ to Entities, and here is a summary:
-
Visual Studio Entity Data Model Wizard Not Responding
This post is for the issue that Entity Data Model Wizard becomes not responding. In Visual Studio 2015, when clicking the Finish button to create the entity data model from SQL Server 2014 SP! database, the wizard is frozen:
-
Entity Framework and LINQ to Entities (9) Optimistic Concurrency
Conflicts can occur if the same piece of data is read and changed concurrently. Generally, there are 2 concurrency control approaches:
-
Entity Framework and LINQ to Entities (8) Transactions
As discussed above, by default DbContext.SaveChanges execute all data creation, update and deletion in a transaction, so that all the work can succeed or fail as a unit. The following example tries to update 2 entities, so there will be 2 UPDATE statements in the transaction:
-
Understanding C# Features (8) Covariance and Contravariance
[LINQ via C#] - [C# Features]
-
Sync Windows Live Writer Drafts and Posts Across PCs
Windows Live Writer saves drafts and posts under Documents\My Weblog Posts. To sync this directory with OneDrive, just move it to OneDrive (e.g. OneDrive\Documents\WindowsLiveWriter), and create a junction to redirect:
-
C# 6.0 String Interpolation, FormattableString, and Code Analysis CA1305: Specify IFormatProvider
C# 6.0 introduces a syntactic sugar string interpolation, it is safer and more readable than composite formatting. Here is a small example:
-
DiskPart Problem: Cannot Select Partition
When working with USB drive, the DiskPart command cannot select the partition of the USB disk:
-
Understanding C# Features (7) Higher-Order Function
[LINQ via C#] - [C# Features]
-
Understanding C# Features (6) Closure
[LINQ via C#] - [C# Features]
-
Entity Framework and LINQ to Entities (1) IQueryable<T> and Remote Query
The previous chapters discussed LINQ to Objects, LINQ to XML (objects), and Parallel LINQ (to Objects). All of these APIs query in memory objects managed by .NET. This chapter discusses Entity Framework, a Microsoft library providing a different kind of LINQ technology, LINQ to Entities. LINQ to Entities can access and query relational data managed by different kinds of databases, e.g.:
-
End-to-end: Setup continuous integration/continuous delivery for ASP.NET Core + SQL database with GitHub, AppVeyor and Azure
I have a web project “Chinese Etymology (http://hanziyuan.net)” for searching Chinese character’s etymologies and ancient Chinese characters. It is developed with Microsoft tech stack – ASP.NET Core + SQL database. It is open source on GitHub. Its database is deployed to Azure SQL Database, and the website is deployed to Azure App Service. I will use this project to demonstrate the end-to-end workflow and setup for continuous integration/continuous delivery with AppVeyor. After these steps, when you commit code and push to your repository
-
Easy Ways to Test SQL Server/SQL Azure Connection
It is incredibly easy to test the SQL Server/Azure SQL Database connectivity or firewall settings from Windows, even without SSMS (SQL Server Management Studio) or coding.
-
Detect Chinese Character in Unicode String
Recently, when trying to convert some directory/file names between Chinese and English, it is necessary to detect if a Unicode string contains Chinese characters. Unfortunately, Chinese language detection, or language detection, is not easy. There are several options:
-
Entity Framework and LINQ to Entities (7) Data Changes
Besides LINQ to Entities queries, Entity Framework also provides rich APIs for data changes.