This blog is a knowledge base...where I clip cool tricks and urls

diving into LINQ

In my last column I talked about LINQ as the key feature in .NET 3.5. ASP.NET 3.5 is not going to see a whole bunch of new features only just a few new controls and the roll up of some of the slip stream features like Microsoft ASP.NET AJAX and IIS 7 support directly rolled into the .NET framework. The big news in ASP.NET 3.5, and .NET 3.5 in general, is LINQ and its related new features. In the last column I introduced some key features of LINQ and why I think it’s easily the most important feature in .NET 3.5. This time I’ll take a closer look at the data specific LINQ features in LINQ to SQL.
Unwrapping LINQ to SQL
 blog it

clean CSS separation

clipped from weblogs.asp.net


VS 2008 Web Designer and CSS Support

One of the big features that web developers will quickly discover with VS 2008 is its dramatically improved HTML designer, and the rich CSS support it brings. 
VS 2008 now uses the same web designer that ships with Microsoft's new Expression Web product.  In addition to providing lots of new functionality, you'll also find that this web designer is much faster than the VS 2005 version (which was based on a much older code base).
VS 2008 supports a new tool window inside the IDE called "Manage Styles".  This shows all of the CSS stylesheets, and their corresponding rules, for the page you are currently editing.  It can be used both when you are in design-view, as well as when you are in source view on a page:
 blog it

MVC in ASP.NET part 2

clipped from weblogs.asp.net
The ASP.NET MVC Framework enables you to use any data access pattern or framework you want in order to retrieve and manage your models.  If you want to use ADO.NET DataSets/DataReaders (or abstractions built on top of them) you can.  If you prefer to use an object relational mapper (ORM) like NHibernate, LLBLGen, WilsonORMapper, LINQ to SQL/LINQ to Entities you can absolutely use those as well.
For our e-commerce sample application I'm going to use the built-in LINQ to SQL ORM shipped in .NET 3.5 and VS 2008.  You can learn more about LINQ to SQL from my ongoing blog tutorial series that covers it (in particular make sure to check out my Part1, Part2, Part3 and Part4 posts). 
Mapping URL Parameters to Controller Action Methods
 blog it

MVC in ASP.NET

clipped from weblogs.asp.net
In most web frameworks (ASP, PHP, JSP, ASP.NET WebForms, etc), incoming URLs typically map to template files stored on disk.  For example, a "/Products.aspx" or "/Products.php" URL typically has an underlying Products.aspx or Products.php template file on disk that handles processing it.  When a http request for a web application comes into the web server, the web framework runs code specified by the template file on disk, and this code then owns handling the processing of the request.  Often this code uses the HTML markup within the Products.aspx or Products.php file to help with generating the response sent back to the client.
 blog it

Avoid Loops in Excel

clipped from www.ozgrid.com
To put it bluntly I very often avoid Loops, they are far too
slow in many cases. A common mistake we all make when first learning VBA is to use Loops when we really shouldn't. Take the simple example below for instance. It Loops through a range and places the word "Blank" in each blank cell within a
used range, i.e it assumes the last occupied cell is D500
Sub WrongWay()
Dim Bcell As Range
For Each Bcell In Range("A1:D500")
If IsEmpty(Bcell) Then Bcell = "Blank"
Next Bcell
End Sub
Now compare the above code to this one:
Sub RightWay()
If WorksheetFunction.CountA(Range("A1:D500")) = 0 Then
MsgBox "All cells are empty", vbOKOnly, "OzGrid.com"
Exit Sub
End If
On Error Resume Next
Range("A1:D500").SpecialCells(xlCellTypeBlanks) = "Blank"
On Error GoTo 0
End Sub
 blog it

LINQ need primary key

what the fuck??
clipped from blog.benhall.me.uk
Type: System.InvalidOperationException
Source: System.Data.Linq
TargetSite: Void Attach(T)
HelpLink: null
Stack: at System.Data.Linq.Table`1.Attach(T item)
at SqlServer.SqlContentProvider.SaveDocument(Document document) in E:\My Documents\Visual Studio Codename Orcas\Projects\SqlServer\SqlContentProvider.cs:line 53
at SimpleWiki.DAL.Tests.DocumentTests.TestInsertingDocument() in E:\My Documents\Visual Studio Codename Orcas\Projects\Tests\DocumentTests.cs:line 28

I thought I had everything correctly, however I forgot to set a primary key in the table, hence Linq was unable to do anything with the object.  So, lesson for the day Linq must have a Primary key for the table :).

 blog it

convert with generics

clipped from nayyeri.net

Who has said we should write a simple code?!!  I used List<T>.ConvertAll() function to get a List<String> from a List<Double> then converted my List<String> to an Array of Strings.

List<T>.ConvertAll() method is a new .NET 2.0 Generic method which gets a System.Converter object and converts each element in a List<T> from type T to the outgoing type.  It seems this method is using a predicate but actually it doesn't do this.

public String Points

{

    get

    {

        return String.Join(" | ",

            (String[])this.myStudent.Points.ConvertAll

            (new Converter<Double, String>(delegate(Double value)

            {

                return Convert.ToString(value);

            }

            )).ToArray());

    }

}

 blog it

BBuilder - Open source batch builder

clipped from www.codeproject.com
Screenshot - BBuilder1.png

Introduction

One day my friend told me he needed to change his way of releasing builds. It meant he had to fix a batch to compile and publish several products. Such a process can be tedious since it has to be very reliable and you have to remember all the required DOS commands. Each step of a batch is in fact a command that can be accomplished in pure DOS or executing external executable files. So I thought it would be cool to make a batch editor in the following way:


  1. Choose a command from a toolbox

  2. Support re-ordering

  3. Save it to disk for further use

  4. Visualize all commands in a simple way

  5. Enable adding custom tools as plug-ins

  6. Test the batch before it goes somewhere (Scheduled Tasks) with optimizations

Background

Screenshot - BBuilder2.png
 blog it

GridView DataBind LINQ to ASP.NET controls

Cool!
clipped from weblogs.asp.net
Over the last few weeks I've been writing a series of blog posts that cover LINQ to SQL.  LINQ to SQL is a built-in O/RM (object relational mapper) that ships in the .NET Framework 3.5 release, and which enables you to easily model relational databases using .NET classes.  You can use LINQ expressions to query the database with them, as well as update/insert/delete data.
Below are the first four parts of my LINQ to SQL series:
In today's blog post I'll cover the new <asp:LinqDataSource> control that is shipping as part of ASP.NET in the upcoming .NET 3.5 release.  This control is a new datasource control for ASP.NET (like the ObjectDataSource and SQLDataSource controls that shipped with ASP.NET 2.0) which makes declaratively binding ASP.NET UI controls to LINQ to SQL data models super easy.
Sample Application We'll be Building
 blog it

ASP.NET MVC

Was it inspired by Django???
clipped from weblogs.asp.net


#

re: ASP.NET MVC Framework



Monday, October 15, 2007 3:22 AM
by
Brandon Bloom

I am a C# junkie, but I use Django for web development because ASP.net places far too much focus on the designer. With Django, I find an artist to do the CSS file and I just make a bunch of divs in the template.

Looks like you guys nailed it with this. Maybe I'll starting using ASP.net when this is available. Awesome stuff :-)

 blog it

Tuning Performance - LINQ to SQL

clipped from davidhayden.com
LINQ To SQL - Lazy Loading Properties and Specifying PreFetch When Needed - Sweet Query and Performance Control
This is another post in a series of posts on LINQ To SQL in how I think I have discovered a potential performance problem of LINQ To SQL only to find an elegant solution to the problem using LINQ To SQL. If you haven't been reading along with the discovery, here are a few previous posts on LINQ To SQL in this discussion of performance and query tuning:
 blog it

LINQ Overview

LINQ to SQL allows .NET developers to write “queries” in their .NET language of choice to retrieve and manipulate data from a SQL Server database. In a general sense, LINQ to SQL allows us to create SQL queries in our preferred .NET language syntax and work with a strongly types collection of objects as a return result. We can make changes to these objects then save changes back to the database.
Image
HookedOnLINQ db = 
new HookedOnLINQ("Data Source=(local);Initial Catalog=HookedOnLINQ");
var q = from c in db.Contact
where c.DateOfBirth.AddYears(35) > DateTime.Now
orderby c.DateOfBirth descending
select c;
foreach(var c in q)
Console.WriteLine("{0} {1} b.{2}",
c.FirstName.Trim(),
c.LastName.Trim(),c.DateOfBirth.ToString("dd-MMM-yyyy"));
Output:
Mack Kamph b.17-Sep-1977
Armando Valdes b.09-Dec-1973
 blog it

Local database sdf in VS2008

Is this the new way to cache and synchronized data?
clipped from channel9.msdn.com
preview
In this interview Milind Lele, Program Manager on the Visual Basic Team, shows us his favorite features - the new Data Synchronization designer in Visual Studio 2008 and how the sync services for ADO.NET work to support occasionally connected scenarios. He shows us how to set up a local database cache using SQL Compact Edition and how to use it to store read-only data caches as well as how to add the code to support two-way synchronization.
 blog it

Introduction to LINQ

clipped from weblogs.asp.net

What Is LINQ to SQL?

LINQ to SQL is an O/RM (object relational mapping) implementation that ships in the .NET Framework "Orcas" release, and which allows you to model a relational database using .NET classes.  You can then query the database using LINQ, as well as update/insert/delete data from it.

LINQ to SQL fully supports transactions, views, and stored procedures.  It also provides an easy way to integrate data validation and business logic rules into your data model.

Modeling Databases Using LINQ to SQL:

Visual Studio "Orcas" ships with a LINQ to SQL designer that provides an easy way to model and visualize a database as a LINQ to SQL object model.  My next blog post will cover in more depth how to use this designer (you can also watch this video I made in January to see me build a LINQ to SQL model from scratch using it). 

Using the LINQ to SQL designer I can easily create a representation of the sample "Northwind" database like below:

 blog it

WPF. Draggable objects and simple shape connectors.

WPF. Draggable objects and simple shape connectors.

Each shape can possibly be connected to any number of another shapes. For hanling the position of each connector while dragging the object we need to somehow control the start and end points of the line element connected to two shapes. So it becomes obvious that each shape should contain the list of line's start and end points separately so that line positioning and length can be easily updated by the shape itself or outter code.

shapeconnectors_1
 blog it

Json.net

use JSON instead XML

Json.NET



09 September 2007
Filed under: ,


The Json.NET library makes working with JavaScript and JSON formatted data in .NET simple. Quickly read and write JSON using the JsonReader and JsonWriter or serialize your .NET objects with a single method call using the JsonSerializer. 

Json.NET CodePlex Project

Json.NET Download



Product product = new Product();

product.Name = "Apple";

product.Expiry = new DateTime(2008, 12, 28);

product.Price = 3.99M;

product.Sizes = new string[] { "Small", "Medium", "Large" };

 

string json = JavaScriptConvert.SerializeObject(product);

//{

//  "Name": "Apple",

//  "Expiry": new Date(1230422400000),

//  "Price": 3.99,

//  "Sizes": [

//    "Small",

//    "Medium",

//    "Large"

//  ]

//}

 

Product deserializedProduct = JavaScriptConvert.DeserializeObject<Product>(json);


 blog it

linq book

clipped from www.manning.com
Part I - Getting started

 1. Introducing LINQ - FREE

 2. C# and VB.NET language enhancements - AVAILABLE

 3. LINQ building blocks - AVAILABLE

Part II - Querying objects in memory

 4. Getting familiar with LINQ to Objects - AVAILABLE

 5. Working with LINQ and DataSets - AVAILABLE

 6. Beyond basic in-memory queries - AVAILABLE

Part III - Mapping objects to relational databases

 7. Getting started with LINQ to SQL - AVAILABLE

 8. Peeking under the covers - AVAILABLE

 9. Advanced LINQ to SQL features - AVAILABLE
 blog it

Open Source Batch Editor

BBuilder on code project
clipped from www.codeproject.com
Screenshot - BBuilder1.png

Points of Interest




  1. Reflection for a flexible application

  2. Factory and Singleton design patterns

  3. IComparer implementation to generate a custom order

  4. Creating a windows application in .NET with a professional look like Outlook. With a powerful grid that overrides the Rendering

  5. Spawn process for Shell : Redirecting input/output

  6. Make a responsive UI with Background worker

  7. Deploying the application with a Setup project, with custom file type and icons
 blog it