Andy The's Blog
Saturday, July 3, 2010
Saturday, October 24, 2009
Output your SQL when using Linq in ASP.NET
I used both Linq Data Source and straight Linq.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
StringWriter sw = new StringWriter();
protected void Page_Load()
{
// Using Linq Data Source
LinqDataSource1.ContextCreated += (sender, e) =>
{
sw.WriteLine("Grid 1 SQL");
((DataClassesDataContext)e.Result).Log = sw;
};
// Using Linq
DataClassesDataContext db = new DataClassesDataContext();
var results = from c in db.Customers
where c.City == "London"
select c;
GridView2.DataSource = results;
sw.WriteLine("Grid 2 SQL");
db.Log = sw;
GridView2.DataBind();
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
writer.Write("<hr><p>LINQ to SQL Trace Console</p><p><textarea cols='100' rows='15' readonly='true'>");
writer.Write(sw.ToString());
writer.Write("</textarea></p>");
}
}
Wednesday, October 21, 2009
Mass installing your DNN modules
Step 1) Drop your module in:
{Where your DNN is installed}\Install\Module
Step 2) Go to this URL:
http://{yoursite}/install/install.aspx?mode=installresources
You should see your modules being installed.
Finished.
Wednesday, October 14, 2009
Disk2vhd v1.0
http://technet.microsoft.com/en-nz/sysinternals/ee656415(en-us).aspx
Disk2vhd will create a vhd out of your hard drive.
Tuesday, October 13, 2009
Generate your own custom Controller and Views by overriding the default MVC T4 templates
Create a ASP.NET MVC Web Application
Copy the CodeTemplates directory into the root of your MVC project.
By copying this directory into your root directory you will be overriding the default templates.
The CodeTemplates directory can be found here:
C#
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC
or
VB.NET
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\Web\MVC
Highlight each t4 template and delete the “Custom Tool” properties.
Modify template(s)
Add new controller
Now you can see your custom created controller!!!
(This applies to the views as well)