Thanks to all those who pointed out my settings file was corrupted. This was indeed the case.
Here are the new files:
Random thoughts about development on the Microsoft platform
Viewing entries in
Development
Thanks to all those who pointed out my settings file was corrupted. This was indeed the case.
Here are the new files:
While working on a project involving Silverlight and WCF REST I ran into some errors that didn’t give me much insight into the actual problem.
The error I got was:
System.Net.WebException: The remote server return an error: NotFound
I had a quick question from Justin King just now about how to format a money field to be currency in ASP.NET Dynamic Data.
There are a few ways to do this.
jQuery 1.3 was released and the most useful new feature is the live event!
Previously in older versions when you dynamically added new DOM elements into you page your event handlers would not automatically be attached to those elements.
You run into this issue a lot if you use AJAX or are creating lots of elements on the fly. The only trick before this new feature was to rebind all those events whenever a new element was added.
With the live event, it automatically binds up all current and future elements matching the selector
So instead of using:
// Will only add the event handler to current matched elements in the DOM $("div").click(function() { doSomething(); });
You can use
// Will add the event handler to all current and future matched elements in the DOM $("div").live("click", function() { doSomething(); });
Check it out, it’s a great new feature.
There are two ways to work when using ASP.NET Dynamic Data:
Scaffolding manually is alright but you need to remember to add the ScaffoldTableAttribute to the new tables you want managed by ASP.NET Dynamic Data
I prefer to let it automatically scaffold all tables so as I’m developing and changing the database schema I automatically get the CRUD pages. I then choose which ones to exclude.
Note: You can scaffold all tables by setting the ScaffoldAllTables property to true in your Global.asax.cs
model.RegisterContext(typeof(TestDataContext), new ContextConfiguration() { ScaffoldAllTables = true });
This is great, until you start using the ASP.NET Membership and Role providers. When you use these (integrated into the one database) it adds a lot of aspnet_* tables to your database so when you regenerate your LINQ to Entities/SQL file.
You can avoid these issues if you make ASP.NET generate these tables into a separate database but if you like everything in one database then there is a solution for you. T4 Templates - built right into Visual Studio. We can use these templates to automatically exclude the aspnet tables.
<#@ template language="C#v3.5" hostspecific="True"#> <#@ include file="../L2ST4.ttinclude"#> <#@ output extension=".generated.cs"#> <# // Template by Eric Phan http://ericphan.info inspired by Damien Guard http://damieng.com var data = new Data(Host.TemplateFile.Replace("MetaData.tt","../NAMEOFYOURDBML.dbml")); var code = new CSharpCodeLanguage(); data.Serialization = SerializationMode.DataContractSP1; #> #pragma warning disable 1591 //------------------------------------------------------------------------------ ////------------------------------------------------------------------------------ using System; using System.ComponentModel; using System.Data.Linq; using System.Data.Linq.Mapping; using System.ComponentModel.DataAnnotations; using <#=data.EntityNamespace#>.MetaData; namespace <#=data.EntityNamespace#>.MetaData { <# foreach(Table table in data.Tables) { foreach(TableClass class1 in table.Classes) { if (class1.Name.StartsWith("Aspnet_")) {#> [ScaffoldTable(false)]<#}#> public partial class <#=class1.Name#>MetaData {<# if (class1.Columns.Count > 0) foreach(Column column in class1.Columns) if (column.IsPrimaryKey) { #> [ScaffoldColumn(false)] public object <#=column.Member#> { get; set; } <#}#> } <#}}#>} namespace <#=data.EntityNamespace#> { <# foreach(Table table in data.Tables) { foreach(TableClass class1 in table.Classes) { #> [MetadataType(typeof(<#=class1.Name#>MetaData))] public partial class <#=class1.Name#> { } <#}}#> } #pragma warning restore 1591
// This code was generated by LINQ to SQL template for T4 C# v0.79
// Generated at <#=DateTime.Now#>
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
Note: MetaData.tt will create all partial classes based on your DBML file, create the associated metadata classes and associate them to the class. It will also add the ScaffoldTable(false) attribute to any Aspnet tables and automatically unscaffold any primary key columns (workaround for GUID issue)