<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Ricka on MVC &amp; Dynamic Data</title><subtitle type="html">Interesting tidbits on MVC and Dynamic Data not found in MSDN.</subtitle><id>http://blogs.msdn.com/rickandy/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/rickandy/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-09-25T20:58:00Z</updated><entry><title>Should my database calls be Asynchronous?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/11/14/should-my-database-calls-be-asynchronous.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2009/11/14/should-my-database-calls-be-asynchronous.aspx</id><published>2009-11-14T01:10:02Z</published><updated>2009-11-14T01:10:02Z</updated><content type="html">Long running/expensive database calls might seem like a natural candidate for asynchronous calls. Suppose you have the following system: A web application running on IIS 7 /.NET Framework v3.5 SP1 using the default request gating ( maxConcurrentRequestsPerCPU =&amp;quot;12&amp;quot;) Your server is a dual. You are not using asynchronous methods. Your web application contains a mix of static content, quick running dynamic pages, and a few very slow pages that hit the DB. (The DB is the bottleneck on these...(&lt;a href="http://blogs.msdn.com/rickandy/archive/2009/11/14/should-my-database-calls-be-asynchronous.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9922356" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author></entry><entry><title>Tips on getting your ASP.NET MVC questions answered quickly</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/10/29/tips-on-getting-your-asp-net-mvc-questions-answered-quickly.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2009/10/29/tips-on-getting-your-asp-net-mvc-questions-answered-quickly.aspx</id><published>2009-10-29T21:22:00Z</published><updated>2009-10-29T21:22:00Z</updated><content type="html">When you run into an issue or have a question about ASP.NET MVC the best place for it is the MVC Forum . When you write your question, there are a few simple things that you can do to make it easier for the ‘experts’ to answer (and hence to get an answer quicker!). 1. Mention what environment you’re running in What web server are you using Most likely, you are using either “Cassini” (the test web server built in Visual Studio), IIS6 (XP), or IIS7 (on Vista, Windows 7 or Windows Server 2008). In many...(&lt;a href="http://blogs.msdn.com/rickandy/archive/2009/10/29/tips-on-getting-your-asp-net-mvc-questions-answered-quickly.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9914951" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author></entry><entry><title>MVC FAQ</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/10/15/mvc-faq.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2009/10/15/mvc-faq.aspx</id><published>2009-10-15T19:43:00Z</published><updated>2009-10-15T19:43:00Z</updated><content type="html">Technorati Tags: MVC Please post corrections/submissions to the MVC Forum . Include MVC FAQ in the title. Post LINQ to SQL To SQL Questions here Post Entity Framework Questions here Q: How do I get started with MVC? Walkthrough: Creating a Basic MVC Project with Unit Tests in Visual Studio Walkthrough: Using Templated Helpers to Display Data Includes a VB/C# sample. (Requires MVC 2) How to: Validate Model Data Using DataAnnotations Attributes (Shows how to use Entity Framework with MVC) Includes...(&lt;a href="http://blogs.msdn.com/rickandy/archive/2009/10/15/mvc-faq.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9907816" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author></entry><entry><title>Client Side Validation for MVC 2 P2</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/10/03/client-side-validation-for-mvc-2-p2.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="30075" href="http://blogs.msdn.com/rickandy/attachment/9902629.ashx" /><id>http://blogs.msdn.com/rickandy/archive/2009/10/03/client-side-validation-for-mvc-2-p2.aspx</id><published>2009-10-03T02:30:00Z</published><updated>2009-10-03T02:30:00Z</updated><content type="html">MVC 2 Preview 1 added support for DataAnnotations . In my MSDN article How to: Validate Model Data Using DataAnnotations Attributes I covered the basics of validation. Preview 2 adds client validation with the addition of one line of code. The following class contains the model I use in my sample download . public class Pals { [ Required ()] [ Range (33,99)] public float Height { get ; set ; } [ Required ()] [ StringLength (7)] public string Name { get ; set ; } [ ScaffoldColumn ( false )] public...(&lt;a href="http://blogs.msdn.com/rickandy/archive/2009/10/03/client-side-validation-for-mvc-2-p2.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9902629" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author></entry><entry><title>DRY-ing out the MVC 2 Templated Helpers</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/08/18/dry-ing-out-the-mvc-2-templated-helpers.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="288124" href="http://blogs.msdn.com/rickandy/attachment/9874659.ashx" /><id>http://blogs.msdn.com/rickandy/archive/2009/08/18/dry-ing-out-the-mvc-2-templated-helpers.aspx</id><published>2009-08-18T22:15:00Z</published><updated>2009-08-18T22:15:00Z</updated><content type="html">In my MSDN article Using Templated Helpers to Display Data , I show how they provide a very productive means of building a UI for data sets. The code below shows a typical use of the Display and Label helpers. &amp;lt; span style =" font-weight : bold ; "&amp;gt; &amp;lt;% = Html.Label( "Name" ) %&amp;gt; : &amp;lt;/ span &amp;gt; &amp;lt;% = Html.Display( "Name" ) %&amp;gt; &amp;lt; br /&amp;gt;&amp;lt; span style =" font-weight : bold ; "&amp;gt; &amp;lt;% = Html.LabelFor(Pals =&amp;gt; Pals.ID) %&amp;gt; : &amp;lt;/ span &amp;gt; &amp;lt;% = Html.DisplayFor(Pals =&amp;gt;...(&lt;a href="http://blogs.msdn.com/rickandy/archive/2009/08/18/dry-ing-out-the-mvc-2-templated-helpers.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9874659" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="ASP.Net" scheme="http://blogs.msdn.com/rickandy/archive/tags/ASP.Net/default.aspx" /><category term="MVC" scheme="http://blogs.msdn.com/rickandy/archive/tags/MVC/default.aspx" /></entry><entry><title>Using DataAnnotations in MVC 2 - Catching up to Dynamic Data</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/08/01/using-dataannotations-in-mvc-2-catching-up-to-dynamic-data.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2009/08/01/using-dataannotations-in-mvc-2-catching-up-to-dynamic-data.aspx</id><published>2009-08-01T10:39:00Z</published><updated>2009-08-01T10:39:00Z</updated><content type="html">DataAnnotations help you write robust validation and prevent the type of annoying error message shown above. Form submittal failure when a field doesn’t validate can be very frustrating - especially when there is no indication of the problematic property or the constraint violation. I happened to get the Outlook error above when I attempted to submit a mail message to the MVC QA guys. It turns out the distribution list I made for them a few days earlier had problems. The image below (From my sample...(&lt;a href="http://blogs.msdn.com/rickandy/archive/2009/08/01/using-dataannotations-in-mvc-2-catching-up-to-dynamic-data.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9847028" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="ASP.Net" scheme="http://blogs.msdn.com/rickandy/archive/tags/ASP.Net/default.aspx" /><category term="MVC" scheme="http://blogs.msdn.com/rickandy/archive/tags/MVC/default.aspx" /></entry><entry><title>New Templated Helpers Improve SoC</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/07/24/new-templated-helpers-improve-soc.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2009/07/24/new-templated-helpers-improve-soc.aspx</id><published>2009-07-24T04:08:15Z</published><updated>2009-07-24T04:08:15Z</updated><content type="html">SoC (from WikiPedia) In my MSDN article Walkthrough: Using Templated Helpers to Display Data I show how to annotate your data model to specify that a field should be rendered with a type-specific control. The download sample code also includes a control using the new Html.EditorFor helper. With one line of code you can open an editor on your strongly typed object. Using the line below, my edit/create view can instantiate an editor on the Product object. &amp;lt;% = Html.EditorFor(Product=&amp;gt; Model)...(&lt;a href="http://blogs.msdn.com/rickandy/archive/2009/07/24/new-templated-helpers-improve-soc.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9847021" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author></entry><entry><title>Setting font attributes with UIHint in your Entity Partial Class</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/06/02/setting-font-attributes-with-uihint-in-your-entity-partial-class.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="1514399" href="http://blogs.msdn.com/rickandy/attachment/9686137.ashx" /><id>http://blogs.msdn.com/rickandy/archive/2009/06/02/setting-font-attributes-with-uihint-in-your-entity-partial-class.aspx</id><published>2009-06-02T17:41:00Z</published><updated>2009-06-02T17:41:00Z</updated><content type="html">I've written a simple Field Template ( RedBold.ascx ) that reads most font attributes and applies them to your field values. The new entity templates make it easy to apply font attributes to the field labels. The image below shows several font attributes applied to the partial class for the Customer table of the AdventureWorksLT database. You can apply attributes (bold, italic, foreground color, background color, border style, border color, font name, etc) to the field name or the field value. For...(&lt;a href="http://blogs.msdn.com/rickandy/archive/2009/06/02/setting-font-attributes-with-uihint-in-your-entity-partial-class.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9686137" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="Dynamic Data" scheme="http://blogs.msdn.com/rickandy/archive/tags/Dynamic+Data/default.aspx" /></entry><entry><title>Dynamic Data FAQ</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2009/01/08/dynamic-data-faq.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2009/01/08/dynamic-data-faq.aspx</id><published>2009-01-08T13:03:00Z</published><updated>2009-01-08T13:03:00Z</updated><content type="html">&lt;P&gt;&lt;STRONG&gt;&lt;FONT size=4&gt;Please post corrections/new submissions to the &lt;/FONT&gt;&lt;A href="http://forums.asp.net/1145.aspx" target=_blank&gt;&lt;FONT size=4&gt;Dynamic Data Forum&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=4&gt;. &lt;/FONT&gt;&lt;FONT size=2&gt;Put &lt;FONT color=#800000&gt;&lt;EM&gt;FAQ&lt;/EM&gt; &lt;EM&gt;Submission/Correction&lt;/EM&gt;&lt;/FONT&gt; in your title.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;See &lt;A href="http://blogs.msdn.com/davidebb/archive/2009/01/11/tips-on-getting-your-asp-net-dynamic-data-questions-answered-quickly.aspx" target=_blank&gt;Tips on getting your ASP.NET Dynamic Data questions answered quickly&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Post &lt;A href="http://msdn.microsoft.com/en-us/vcsharp/aa904594.aspx" target=_blank&gt;LINQ&lt;/A&gt; To SQL Questions &lt;A href="http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/threads/" target=_blank&gt;here&lt;/A&gt;&lt;BR&gt;Post Entity Framework Questions &lt;A href="http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/threads/" target=_blank&gt;here&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Links that will answer questions:&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;From the Dynamic Data architect &lt;A href="http://blogs.msdn.com/davidebb/default.aspx" target=_blank&gt;David Ebbo&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/12/11/handling-database-exceptions-in-dynamic-data.aspx" target=_blank&gt;Handling database exceptions in Dynamic Data&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2009/01/09/a-helper-to-easily-set-up-change-notifications-in-entity-framework.aspx" target=_blank&gt;A helper to easily set up change notifications in Entity Framework&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/12/22/two-worlds-of-dynamic-data-customization-generic-vs-schema-specific.aspx" target=_blank&gt;Two worlds of Dynamic Data customization: generic vs schema specific&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/12/11/using-dynamic-data-with-multiple-databases.aspx" target=_blank&gt;Using Dynamic Data with multiple databases&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/11/26/fun-with-t4-templates-and-dynamic-data.aspx"&gt;Fun with T4 templates and Dynamic Data&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/11/25/using-user-controls-as-page-templates-in-dynamic-data.aspx"&gt;Using User Controls as Page Templates in Dynamic Data&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/10/25/a-many-to-many-field-template-for-dynamic-data.aspx"&gt;A ‘Many To Many’ field template for Dynamic Data&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/06/18/using-asp-net-dynamic-data-with-objectdatasource.aspx"&gt;Using ASP.NET Dynamic Data with ObjectDataSource&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/06/16/dynamic-data-and-the-associated-metadata-class.aspx"&gt;Dynamic Data and the Associated Metadata Class&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/06/13/understanding-foreign-keys-and-relationship-columns-in-dynamic-data.aspx"&gt;Understanding foreign keys and relationship columns in Dynamic Data&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/05/27/sample-dynamic-data-and-attribute-based-permissions.aspx"&gt;Sample: Dynamic Data and attribute based permissions&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/davidebb/archive/2008/05/25/dynamic-data-ajax-and-javascript-errors.aspx"&gt;Dynamic Data, AJAX and JavaScript errors&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;From &lt;/STRONG&gt;&lt;A href="http://blogs.msdn.com/rickAndy"&gt;&lt;STRONG&gt;http://blogs.msdn.com/rickAndy&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;&amp;nbsp; (Most samples include VB)&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/rickandy/archive/2008/12/09/explicit-connection-string-for-ef.aspx"&gt;Explicit connection string for EF&lt;/A&gt; and L2S 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/rickandy/archive/2008/12/31/custom-validation-error-message-not-displayed.aspx"&gt;Custom Validation Error message not displayed&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/rickandy/archive/2008/11/22/improving-the-fk-field-display-showing-two-fields-in-foreign-key-columns-with-ef.aspx"&gt;Improving the FK field display: Showing two fields in Foreign Key columns&lt;/A&gt;&amp;nbsp; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/rickandy/archive/2008/10/04/how-to-create-an-updateable-view-with-ado-entity-framework.aspx"&gt;How to create an updateable view with ADO Entity Framework and with LINQ to SQL&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/rickandy/archive/2008/09/25/tweaking-the-filter-repeater.aspx"&gt;Tweaking the Filter Repeater&lt;/A&gt;&amp;nbsp; When you have too many FK to display in the filter repeater.&lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;From ASP.Net Developer &lt;A href="http://weblogs.asp.net/davidfowler" target=_blank&gt;David Fowler&lt;/A&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://weblogs.asp.net/davidfowler/archive/2008/12/14/autofieldgenerator.aspx" target=_blank&gt;AutoFieldGenerators&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://weblogs.asp.net/davidfowler/archive/2008/12/14/dynamic-listview-layouttemplate.aspx"&gt;Dynamic ListView LayoutTemplate&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://weblogs.asp.net/davidfowler/archive/2008/12/11/dynamic-sorting-with-linq.aspx"&gt;Dynamic Sorting with Linq&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How do I get started with Dynamic Data?&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A: &lt;/STRONG&gt;If you like videos, see &lt;A href="http://www.asp.net/dynamicdata/" target=_blank mce_href="http://www.asp.net/dynamicdata/"&gt;ASP.NET Dynamic Data videos&lt;/A&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="http://msdn.microsoft.com/en-us/library/cc488545.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/cc488545.aspx"&gt;MSDN on Dynamic Data&lt;/A&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="http://msdn.microsoft.com/en-us/library/cc488469.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/cc488469.aspx"&gt;Walkthrough: Creating a New ASP.NET Dynamic Data Web Site Using Scaffolding&lt;/A&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A title=http://www.asp.net/dynamicdata/ href="http://www.asp.net/dynamicdata/" mce_href="http://www.asp.net/dynamicdata/"&gt;http://www.asp.net/dynamicdata/&lt;/A&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="http://forums.asp.net/1145.aspx" target=_blank mce_href="http://forums.asp.net/1145.aspx"&gt;Dynamic Data Forum&lt;/A&gt;&lt;/P&gt;&lt;STRONG&gt;Q: What's new with Dynamic Data for .Net 4 Beta?&amp;nbsp; &lt;FONT color=#ff0000&gt;&amp;lt;-- New&lt;BR&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A: See &lt;A href="http://forums.asp.net/t/1425089.aspx"&gt;this link&lt;/A&gt;.&lt;/STRONG&gt; 
&lt;P&gt;&lt;STRONG&gt;Q: The data annotation to my partial class is not working?&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A: &lt;/STRONG&gt;The most common problem is no namespace or incorrect namespace around your partial class. A partial class that is not part of the data model (or part of another class) is known as a naked partial class. The easiest way to test if you have a naked partial class is to add a non-existing field to the partial class. In the following snippet,&amp;nbsp; &lt;STRONG&gt;bogus&lt;/STRONG&gt; is not in the &lt;STRONG&gt;CustomerAddress&lt;/STRONG&gt; table. &lt;/P&gt;&lt;PRE class=code&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;MetadataType&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;CustomerAddressMetaData&lt;/SPAN&gt;))]
   &lt;SPAN style="COLOR: blue"&gt;public partial class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CustomerAddress &lt;/SPAN&gt;{
       &lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CustomerAddressMetaData &lt;/SPAN&gt;{

           [&lt;SPAN style="COLOR: #2b91af"&gt;ScaffoldColumn&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;)]
           &lt;SPAN style="COLOR: blue"&gt;public object &lt;/SPAN&gt;ModifiedDate;

           &lt;SPAN style="COLOR: blue"&gt;public object &lt;/SPAN&gt;bogus;
       }
   }&lt;/PRE&gt;
&lt;P&gt;When you run the Dynamic Data project, you will get the following exception in DefaultModel.RegisterContext (in global.asax):&lt;/P&gt;
&lt;P&gt;&lt;I&gt;The associated metadata type for type 'DynamicDataProject.CustomerAddress' contains the following unknown properties or fields: &lt;I&gt;bogus. Please make sure that the names of these members match the names of the properties on the main type.&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How do I generate GUIDs on inserts?&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A: &lt;/STRONG&gt;You don't, you shouldn't. Let the DB generate them or you will have performance problems. You can modify the data model XML and explicitly state they are DB generated. With the EDM, use StoreGeneratedPattern="Computed"&amp;nbsp; while Linq to SQL uses IsDbGenerated="true"&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How to set Displayformat for a password field?&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A: See Steve's excellent &lt;A href="http://csharpbits.notaclue.net/2009/05/password-fieldtemplates-for-dynamic.html"&gt;Password FieldTemplates for Dynamic Data&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How do I check for duplicates before I insert? (Or get values from the DB for any reason before I insert)&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A: &lt;/STRONG&gt;see &lt;A href="http://forums.asp.net/p/1358255/2794560.aspx"&gt;this post&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How do I mark a columns as read-only?&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A: &lt;/STRONG&gt;see &lt;A href="http://forums.asp.net/p/1375123/2888163.aspx" target=_blank&gt;this post&lt;/A&gt; or &lt;A class="" title=1498010850596349197 name=1498010850596349197&gt;&lt;/A&gt;&lt;A href="http://csharpbits.notaclue.net/2009/01/making-field-read-only-via.html"&gt;Making a Field Read-Only via the ReadOnlyAttribute – Dynamic Data&lt;/A&gt; - Note the next version of Dynamic Data And The &lt;A href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24887"&gt;ASP.NET Dynamic Data 4.0 Preview 3&lt;/A&gt; support the [ReadOnly(true)] attribute.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: Can Dynamic Data use a data model generated by a 3rd party O/RM tool?&lt;BR&gt;&lt;/STRONG&gt;A:The current Dynamic Data needs the following items to work with a technology: &lt;BR&gt;-&amp;nbsp;&amp;nbsp;&amp;nbsp; Technology must support Linq&lt;BR&gt;-&amp;nbsp;&amp;nbsp;&amp;nbsp; DataSource control must exist for the technology&lt;BR&gt;-&amp;nbsp;&amp;nbsp;&amp;nbsp; Dynamic Data ModelProvider must exist for the technology &lt;/P&gt;
&lt;P&gt;An example of one today is LLBLGen: &lt;A href="http://www.llblgen.com/defaultgeneric.aspx" mce_href="http://www.llblgen.com/defaultgeneric.aspx"&gt;http://www.llblgen.com/defaultgeneric.aspx&lt;/A&gt; 
&lt;P&gt;&lt;A href="http://www.hibernate.org/343.html" target=_blank mce_href="http://www.hibernate.org/343.html"&gt;nHibernate&lt;/A&gt; currently does not meet the Linq requirements. 
&lt;P&gt;&lt;STRONG&gt;Q: What DB's are supported?&lt;BR&gt;A: See &lt;A href="http://msdn.microsoft.com/en-us/data/dd363565.aspx" target=_blank&gt;ADO.NET Entity Framework Providers&lt;/A&gt;&lt;/STRONG&gt; 
&lt;P&gt;&lt;STRONG&gt;Q: How do I hide columns from the Edit and other page templates?&lt;/STRONG&gt; &lt;BR&gt;&lt;STRONG&gt;A: &lt;/STRONG&gt;Suppose you want to display the Salary field, but you don't want to show it in the Edit and Insert templates. See Stephens popular tutorial 
&lt;P&gt;&lt;A href="http://csharpbits.notaclue.net/2008/10/dynamic-data-hiding-columns-in-selected.html" target=_blank mce_href="http://csharpbits.notaclue.net/2008/10/dynamic-data-hiding-columns-in-selected.html"&gt;Dynamic Data - Hiding Columns in selected PageTemplates&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How do I disallow navigation links on Foreign Key columns?&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A:&lt;/STRONG&gt; By default, DD displays the first string column in the Foreign Key table in stead of the FK. This is rendered as a link (&lt;FONT color=#ff0000&gt;NavigateUrl&lt;/FONT&gt;) to the FK table. If you're not happy with the default (column shown) use the DisplayColumn attribute on the FK table to specify which property is displayed. See also &lt;A href="http://blogs.msdn.com/rickandy/archive/2008/11/22/improving-the-fk-field-display-showing-two-fields-in-foreign-key-columns-with-ef.aspx"&gt;Improving the FK field display: Showing two fields in Foreign Key columns&lt;/A&gt;. Back to the original question. The easiest way to disable the FK property from being a NavigateUrl is to hide the FK table by annotating your entity partial class with the &lt;A href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.scaffoldtableattribute.aspx" target=_blank&gt;ScaffoldTable&lt;/A&gt;&amp;nbsp;&amp;nbsp; attribute. Note,&amp;nbsp; &lt;A href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.scaffoldtableattribute.aspx" target=_blank&gt;ScaffoldTable&lt;/A&gt;&amp;nbsp;&amp;nbsp; will hide your table. If you want to expose your table but disable the hyperlink - see Stephens excellent blog &lt;A href="http://csharpbits.notaclue.net/2009/01/allow-navigation-on-foreignkey.html"&gt;Allow Navigation on ForeignKey FieldTemplate – Dynamic Data&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How do I move the &lt;FONT color=#0000ff&gt;Edit Delete Details&lt;/FONT&gt; links from the left side (column 0) to the right side of the table.&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A:&lt;/STRONG&gt; Create your own &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.iautofieldgenerator.generatefields.aspx" target=_blank&gt;IAutoFieldGenerator.GenerateFields&lt;/A&gt; and add the command field at the end. (thx David Fowler). See &lt;A href="http://forums.asp.net/p/1379821/2917320.aspx" target=_blank&gt;this post&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How do I implement role based security? (tables/columns visibility dependent on users role).&lt;BR&gt;A: See &lt;A href="http://forums.asp.net/t/1343958.aspx" target=_blank&gt;this&lt;/A&gt; post, and &lt;A href="http://weblogs.asp.net/davidfowler/archive/2008/12/14/autofieldgenerator.aspx"&gt;custom IAutoFieldGenerator&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Q: How do map stored procedures (sprocs) to Inserts and get back the auto generated PK using L2S?&lt;BR&gt;&lt;/STRONG&gt;&lt;STRONG&gt;A:&lt;/STRONG&gt; See &lt;A href="http://weblogs.asp.net/scottgu/archive/2007/08/23/linq-to-sql-part-7-updating-our-database-using-stored-procedures.aspx"&gt;LINQ to SQL (Part 7 - Updating our Database using Stored Procedures)&lt;/A&gt; , &lt;A href="http://msdn.microsoft.com/en-us/library/bb386946.aspx"&gt;Stored Procedures (LINQ to SQL)&lt;/A&gt; and &lt;A href="http://forums.asp.net/t/1412943.aspx"&gt;How to override default insert method of Details View in Dynamic Data&lt;/A&gt; .&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9300193" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="Dynamic Data" scheme="http://blogs.msdn.com/rickandy/archive/tags/Dynamic+Data/default.aspx" /></entry><entry><title>Custom Validation Error message not displayed</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2008/12/31/custom-validation-error-message-not-displayed.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2008/12/31/custom-validation-error-message-not-displayed.aspx</id><published>2009-01-01T01:44:00Z</published><updated>2009-01-01T01:44:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A customer &lt;A href="http://forums.asp.net/t/1365732.aspx" target=_blank mce_href="http://forums.asp.net/t/1365732.aspx"&gt;pointed out&lt;/A&gt; that his Spanish validation error messages were not being displayed; the default Error message was shown instead.&amp;nbsp; I'll use the Products table from the NorthWind Db to reproduce the problem and show a work-around.&lt;/P&gt;
&lt;P&gt;Create a partial class for the Products entity:&lt;/P&gt;&lt;PRE class=csharpcode&gt; [MetadataType(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(ProductsMD))]
    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; Products {
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; ProductsMD {
            [DataType(&lt;SPAN class=str&gt;"dummy"&lt;/SPAN&gt;, ErrorMessage = &lt;SPAN class=str&gt;"El campo debe ser un entero positivo"&lt;/SPAN&gt;)]
            [DisplayName(&lt;SPAN class=str&gt;"En la acción"&lt;/SPAN&gt;)]
            &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; UnitsInStock { get; set; }
        }
    }&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;VB&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;    &amp;lt;MetadataType(&lt;SPAN class=kwrd&gt;GetType&lt;/SPAN&gt;(ProductsMD))&amp;gt; _
&lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Class&lt;/SPAN&gt; Products
        &lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Class&lt;/SPAN&gt; ProductsMD
            &amp;lt;DataType(&lt;SPAN class=str&gt;"dummy"&lt;/SPAN&gt;, ErrorMessage:=&lt;SPAN class=str&gt;"El campo debe ser un entero positivo"&lt;/SPAN&gt;), _
             DisplayName(&lt;SPAN class=str&gt;"En la acción"&lt;/SPAN&gt;)&amp;gt; _
            &lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Property&lt;/SPAN&gt; UnitsInStock() &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;
            &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Property&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Class&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; Class&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;Navigate to the Products table, edit a row, and change the &lt;STRONG&gt;UnitsInStock&lt;/STRONG&gt; to a letter. Select update and you will get a default error message, not the message applied with the &lt;STRONG&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.aspx"&gt;DataType&lt;/A&gt;&lt;/STRONG&gt; attribute. &lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/photos/ricka/images/9258973/original.aspx" mce_src="http://blogs.msdn.com/photos/ricka/images/9258973/original.aspx"&gt; &lt;/P&gt;
&lt;P&gt;The example above was doomed to failure as the &lt;STRONG&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.aspx"&gt;DataType&lt;/A&gt;&lt;/STRONG&gt; attribute above does not match the &lt;A href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatype.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatype.aspx"&gt;&lt;STRONG&gt;DataType&lt;/STRONG&gt;&lt;/A&gt; enum or have a matching field template.&lt;/P&gt;
&lt;P&gt;There are a couple of possible solutions for displaying custom validation errors on integer conversion failure. You can add the compare validator message that will be displayed for any validation error. The code should be added as the last statement of the &lt;STRONG&gt;Page_Load&lt;/STRONG&gt; method in the DynamicData\FieldTemplates\Integer_Edit.ascx.cs&amp;nbsp; (or .vb) file.&lt;/P&gt;
&lt;P&gt;CompareValidator1.ErrorMessage = String.Format(&lt;SPAN class=str&gt;"El campo {0} debe ser un entero"&lt;/SPAN&gt;, Column.DisplayName);&lt;/P&gt;
&lt;P&gt;or for VB&lt;/P&gt;
&lt;P&gt;CompareValidator1.ErrorMessage = &lt;SPAN class=kwrd&gt;String&lt;/SPAN&gt;.Format(&lt;SPAN class=str&gt;"El campo {0} debe ser un entero"&lt;/SPAN&gt;, Column.DisplayName)&lt;/P&gt;
&lt;P&gt;Entering a non-integer such as Z to the &lt;STRONG&gt;units in stock&lt;/STRONG&gt; field now yields the following error message:&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;El campo En la acción debe ser un entero&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Adding the &lt;STRONG&gt;CompareValidator1.ErrorMessage&lt;/STRONG&gt; to the integer template works for every scaffolded integer. &lt;/P&gt;
&lt;P&gt;For more flexibility, you can extract the custom message from the data model partial class. Replace the CompareValidator1.ErrorMessage&amp;nbsp; line above with the following in the &lt;STRONG&gt;Page_Load&lt;/STRONG&gt; method.&lt;/P&gt;&lt;PRE class=csharpcode&gt; var dataTypeAttribute = MetadataAttributes.OfType&amp;lt;DataTypeAttribute&amp;gt;().SingleOrDefault();

 &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (dataTypeAttribute != &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;) {
    CompareValidator1.ErrorMessage = dataTypeAttribute.FormatErrorMessage(Column.DisplayName);
 }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;VB&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; dataTypeAttribute = MetadataAttributes.OfType(Of DataTypeAttribute)().SingleOrDefault() 

&lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; dataTypeAttribute IsNot &lt;SPAN class=kwrd&gt;Nothing&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Then&lt;/SPAN&gt; 
    CompareValidator1.ErrorMessage = dataTypeAttribute.FormatErrorMessage(Column.DisplayName) 
&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;If&lt;/SPAN&gt; &lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;Even simpler than adding a dummy attribute and extracting the error message;&amp;nbsp; use the &lt;A href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.regularexpressionattribute.aspx" target=_blank&gt;&lt;STRONG&gt;RegularExpression&lt;/STRONG&gt;&lt;/A&gt; attribute and allow only positive integers. The following snippet fixes the error message problem without requiring you to extract the error message in the &lt;STRONG&gt;Page_Load&lt;/STRONG&gt; method.&lt;/P&gt;&lt;PRE class=csharpcode&gt;  [MetadataType(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(ProductsMD))]
    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; Products {
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; ProductsMD {
  &lt;SPAN class=rem&gt;//          [DataType("dummy", ErrorMessage = "El campo debe ser un entero positivo")]&lt;/SPAN&gt;
            [RegularExpression(&lt;SPAN class=str&gt;@"^0*[1-9][0-9]*$"&lt;/SPAN&gt;, ErrorMessage = &lt;SPAN class=str&gt;"Must be a entero positivo"&lt;/SPAN&gt;)]
            [DisplayName(&lt;SPAN class=str&gt;"En la acción"&lt;/SPAN&gt;)]
            &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; UnitsInStock { get; set; }
        }
    }&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;VB&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&amp;lt;MetadataType(&lt;SPAN class=kwrd&gt;GetType&lt;/SPAN&gt;(ProductsMD))&amp;gt; _ 
&lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; Partial &lt;SPAN class=kwrd&gt;Class&lt;/SPAN&gt; Products 
    &lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Class&lt;/SPAN&gt; ProductsMD 
&lt;SPAN class=kwrd&gt;Private&lt;/SPAN&gt; _UnitsInStock &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt; 
        &lt;SPAN class=rem&gt;' [DataType("dummy", ErrorMessage = "El campo debe ser un entero positivo")] &lt;/SPAN&gt;
        &amp;lt;RegularExpression(&lt;SPAN class=str&gt;"^0*[1-9][0-9]*$"&lt;/SPAN&gt;, ErrorMessage := &lt;SPAN class=str&gt;"Must be a entero positivo"&lt;/SPAN&gt;)&amp;gt; _ 
        &amp;lt;DisplayName(&lt;SPAN class=str&gt;"En la acción"&lt;/SPAN&gt;)&amp;gt; _ 
        &lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Property&lt;/SPAN&gt; UnitsInStock() &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt; 
            &lt;SPAN class=kwrd&gt;Get&lt;/SPAN&gt; 
                &lt;SPAN class=kwrd&gt;Return&lt;/SPAN&gt; _UnitsInStock 
            &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Get&lt;/SPAN&gt; 
            &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt;(&lt;SPAN class=kwrd&gt;ByVal&lt;/SPAN&gt; value &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Object&lt;/SPAN&gt;) 
                _UnitsInStock = value 
            &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Set&lt;/SPAN&gt; 
        &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Property&lt;/SPAN&gt; 
    &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Class&lt;/SPAN&gt; 
&lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Class&lt;/SPAN&gt; &lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;Notes: &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;We are using the &lt;STRONG&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.aspx"&gt;DataType&lt;/A&gt;&lt;/STRONG&gt; attribute as a dummy attribute so we can extract our custom error message when a validation error occurs. 
&lt;LI&gt;This is a known bug that should be fixed in the next release.&lt;BR&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9259015" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="Dynamic Data" scheme="http://blogs.msdn.com/rickandy/archive/tags/Dynamic+Data/default.aspx" /><category term="ASP.Net" scheme="http://blogs.msdn.com/rickandy/archive/tags/ASP.Net/default.aspx" /></entry><entry><title>Explicit connection string for EF</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2008/12/09/explicit-connection-string-for-ef.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2008/12/09/explicit-connection-string-for-ef.aspx</id><published>2008-12-09T21:05:00Z</published><updated>2008-12-09T21:05:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;The default constructor for the &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"&gt;ObjectContext&lt;/A&gt; class in the&amp;nbsp; Entity Data Model (EDM) retrieves the construction string from the &lt;STRONG&gt;web.config&lt;/STRONG&gt; or &lt;STRONG&gt;app.config&lt;/STRONG&gt; file. If you have multiple data models or need to pass in the the construction string at run time you must use the &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.aspx"&gt;ObjectContext&lt;/A&gt; constructor that takes a construction string. (Note: Be sure to see the bug/work-around at the end of this article.) The follow snippet shows how to build the string for integrated security.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;//  copy connection string from app.config or web.config  &lt;/SPAN&gt;

    &lt;SPAN class=rem&gt;// connectionString="metadata=res://*;&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;// provider=System.Data.SqlClient;&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;// provider connection string=&amp;amp;quot;&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;// Data Source=ricka0;Initial Catalog=Northwind;Persist Security Info=True;&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;// User ID=sa;Password=*(IU89iu;MultipleActiveResultSets=True&amp;amp;quot;"&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;// providerName="System.Data.EntityClient" &lt;/SPAN&gt;
    

    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; UglyConStr() {

        &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; &lt;SPAN class=str&gt;"metadata=res://*;"&lt;/SPAN&gt;
          + &lt;SPAN class=str&gt;"provider=System.Data.SqlClient;"&lt;/SPAN&gt;
          + &lt;SPAN class=str&gt;"provider connection string=';"&lt;/SPAN&gt;  &lt;SPAN class=rem&gt;// Replace &amp;amp;quot with ' (single quote)&lt;/SPAN&gt;
        + &lt;SPAN class=str&gt;"Data Source=ricka0;"&lt;/SPAN&gt;
        + &lt;SPAN class=str&gt;"Initial Catalog=Northwind;"&lt;/SPAN&gt;
        + &lt;SPAN class=str&gt;"Persist Security Info=True;"&lt;/SPAN&gt;
        + &lt;SPAN class=str&gt;"User ID=sa;Password=*(IU89iu;"&lt;/SPAN&gt;
        + &lt;SPAN class=str&gt;"MultipleActiveResultSets=True';"&lt;/SPAN&gt;  &lt;SPAN class=rem&gt;// Replace &amp;amp;quot with ' (single quote)&lt;/SPAN&gt;
            &lt;SPAN class=rem&gt;//    + "providerName=\"System.Data.EntityClient\""&lt;/SPAN&gt;
        ;
    }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;While the construction string above works, it's very ugly. The hair pulling trick to get it working is replacing &lt;STRONG&gt;&amp;amp;quot&lt;/STRONG&gt; with a single quote &lt;STRONG&gt;&lt;FONT size=5&gt;' &lt;/FONT&gt;&lt;/STRONG&gt;as shown in the comments. Using&amp;nbsp; the raw connection string from the config file (using &amp;amp;quot ) results in a misleading error message &lt;STRONG&gt;&lt;EM&gt;Keyword not supported: 'data source'&lt;/EM&gt;&lt;/STRONG&gt;.&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;A much more elegant construction string using SQL connection is shown below.&lt;/P&gt;&lt;PRE class=csharpcode&gt; &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; getConStrSQL() {

        &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; connectionString = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; System.Data.EntityClient.EntityConnectionStringBuilder
        {
            Metadata = &lt;SPAN class=str&gt;"res://*"&lt;/SPAN&gt;,
            Provider = &lt;SPAN class=str&gt;"System.Data.SqlClient"&lt;/SPAN&gt;,
            ProviderConnectionString = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; System.Data.SqlClient.SqlConnectionStringBuilder
            {
                InitialCatalog = &lt;SPAN class=str&gt;"Northwind"&lt;/SPAN&gt;,
                DataSource = &lt;SPAN class=str&gt;"ricka0"&lt;/SPAN&gt;,
                IntegratedSecurity = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;,
                UserID = getUID(),                 &lt;SPAN class=rem&gt;// User ID such as "sa"&lt;/SPAN&gt;
                Password = getPWD(),               &lt;SPAN class=rem&gt;// hide the password&lt;/SPAN&gt;
            }.ConnectionString
        }.ConnectionString;

        &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; connectionString;
    }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;In VB:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;Public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Shared&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;Function&lt;/SPAN&gt; getConStrSQL() &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;String&lt;/SPAN&gt;
     &lt;SPAN class=kwrd&gt;Dim&lt;/SPAN&gt; connectionString &lt;SPAN class=kwrd&gt;As&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;String&lt;/SPAN&gt; = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; System.Data.EntityClient.EntityConnectionStringBuilder() _
         &lt;SPAN class=kwrd&gt;With&lt;/SPAN&gt; {.Metadata = &lt;SPAN class=str&gt;"res://*"&lt;/SPAN&gt;, _
               .Provider = &lt;SPAN class=str&gt;"System.Data.SqlClient"&lt;/SPAN&gt;, _
               .ProviderConnectionString = &lt;SPAN class=kwrd&gt;New&lt;/SPAN&gt; System.Data.SqlClient.SqlConnectionStringBuilder() _
                 &lt;SPAN class=kwrd&gt;With&lt;/SPAN&gt; {.InitialCatalog = &lt;SPAN class=str&gt;"Northwind"&lt;/SPAN&gt;, _
                       .DataSource = &lt;SPAN class=str&gt;"ricka0"&lt;/SPAN&gt;, _
                       .IntegratedSecurity = &lt;SPAN class=kwrd&gt;False&lt;/SPAN&gt;, _
                       .UserID = getUID(), _
                       .Password = getPWD()}.ConnectionString}.ConnectionString
     &lt;SPAN class=kwrd&gt;Return&lt;/SPAN&gt; connectionString
 &lt;SPAN class=kwrd&gt;End&lt;/SPAN&gt; Function&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;The integrated security approach is slightly different.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; getConStrIntegrated() {

        &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; conStrIntegratedSecurity = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; System.Data.EntityClient.EntityConnectionStringBuilder
           {
               Metadata = &lt;SPAN class=str&gt;"res://*"&lt;/SPAN&gt;,
               Provider = &lt;SPAN class=str&gt;"System.Data.SqlClient"&lt;/SPAN&gt;,
               ProviderConnectionString = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; System.Data.SqlClient.SqlConnectionStringBuilder
               {
                   InitialCatalog = &lt;SPAN class=str&gt;"NorthwindEF"&lt;/SPAN&gt;,
                   DataSource = &lt;SPAN class=str&gt;"bing0"&lt;/SPAN&gt;,
                   IntegratedSecurity = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;,
               }.ConnectionString
           }.ConnectionString;

        &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; conStrIntegratedSecurity;
    }&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;For Dynamic Data, simply pass the construction string to the &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metamodel.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metamodel.aspx"&gt;MetaModel&lt;/A&gt; &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metamodel.registercontext.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metamodel.registercontext.aspx"&gt;RegisterContext&lt;/A&gt; as follows. &lt;/PRE&gt;&lt;PRE class=csharpcode&gt; &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; RegisterRoutes(RouteCollection routes) {
        MetaModel model = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MetaModel();


        model.RegisterContext(() =&amp;gt; &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; NorthwindModel.NorthwindEntities(getConStrIntegrated()),
            &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; ContextConfiguration()
            {
                ScaffoldAllTables = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;
            });

        &lt;SPAN class=rem&gt;// Routes omitted for clarity&lt;/SPAN&gt;
    }&lt;/PRE&gt;
&lt;P&gt;Unfortunately, the current version of Dynamic Data doesn't support this approach with EF (L2S does work). To get the page templates to use the connection string you must add the following line to the Page_Load method in the page templates.&lt;/P&gt;&lt;PRE class=csharpcode&gt;GridDataSource.ContextCreating += &lt;SPAN class=kwrd&gt;delegate&lt;/SPAN&gt;(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; ceSender, System.Web.UI.WebControls.EntityDataSourceContextCreatingEventArgs ceArgs) {
            ceArgs.Context = (System.Data.Objects.ObjectContext)table.CreateContext();
        };&lt;/PRE&gt;
&lt;P&gt;The complete Page_Load is below&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Page_Load(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e) {
        table = GridDataSource.GetTable();

         GridDataSource.ContextCreating += &lt;SPAN class=kwrd&gt;delegate&lt;/SPAN&gt;(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; ceSender, System.Web.UI.WebControls.EntityDataSourceContextCreatingEventArgs ceArgs) {
            ceArgs.Context = (System.Data.Objects.ObjectContext)table.CreateContext();
        }; 

        Title = table.DisplayName;
        GridDataSource.Include = table.ForeignKeyColumnsNames;
        InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert);

        &lt;SPAN class=rem&gt;// Disable various options if the table is readonly&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (table.IsReadOnly) {
            GridView1.Columns[0].Visible = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
            InsertHyperLink.Visible = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
        }
    }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9187857" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="Dynamic Data" scheme="http://blogs.msdn.com/rickandy/archive/tags/Dynamic+Data/default.aspx" /><category term="Connection String" scheme="http://blogs.msdn.com/rickandy/archive/tags/Connection+String/default.aspx" /></entry><entry><title>Improving the FK field display: Showing two fields in Foreign Key columns</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2008/11/22/improving-the-fk-field-display-showing-two-fields-in-foreign-key-columns-with-ef.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2008/11/22/improving-the-fk-field-display-showing-two-fields-in-foreign-key-columns-with-ef.aspx</id><published>2008-11-22T06:17:00Z</published><updated>2008-11-22T06:17:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The default scaffold of the &lt;STRONG&gt;CustomerAddress&lt;/STRONG&gt; table in the AdventureWorksLT database poses a problem: Dynamic Data (DD) defaults to using the first string field in the referenced table. In this case, the first string field is the &lt;STRONG&gt;Title&lt;/STRONG&gt; field (Mr,Ms, and so on).&amp;nbsp; The image below shows the problem with the &lt;STRONG&gt;FilterRepeater&lt;/STRONG&gt; drop down list and &lt;STRONG&gt;Customer&lt;/STRONG&gt; column elements.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/photos/ricka/images/9132516/original.aspx" mce_src="http://blogs.msdn.com/photos/ricka/images/9132516/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;We can take a first step toward fixing this issue by creating and annotating a partial class for the&amp;nbsp;&lt;STRONG&gt;Customer&lt;/STRONG&gt; entity. The code below now displays the &lt;STRONG&gt;LastName&lt;/STRONG&gt; field for the customer entity. The &lt;STRONG&gt;&lt;A class="" href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displaycolumnattribute.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displaycolumnattribute.aspx"&gt;DisplayColumn&lt;/A&gt;&lt;/STRONG&gt; attribute tells referring entities which column to use for display instead of the Foreign Key field.&lt;/P&gt;&lt;PRE class=csharpcode&gt; [DisplayColumn(&lt;SPAN class=str&gt;"LastName"&lt;/SPAN&gt;)]
 [MetadataType(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(CustomerMetaData))]
 &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; Customer {
      &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; CustomerMetaData {
   }
 }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	MARGIN: 0em; WIDTH: 100%; BACKGROUND-COLOR: #f4f4f4
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;While the resulting view is an improvement, it’s not there yet. Note that it doesn't distinguish between the customers with non-unique last names, such as Adams or Liu.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/photos/ricka/images/9132521/original.aspx" mce_src="http://blogs.msdn.com/photos/ricka/images/9132521/original.aspx"&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To fix this, we overload the &lt;STRONG&gt;ToString&lt;/STRONG&gt; method for the &lt;STRONG&gt;Customer&lt;/STRONG&gt; partial class as shown below:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;// [DisplayColumn("LastName")]&lt;/SPAN&gt;
[MetadataType(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(CustomerMetaData))]
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; Customer {

     &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;override&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; ToString() {
         &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt; LastName.ToString() + &lt;SPAN class=str&gt;", "&lt;/SPAN&gt; + FirstName.ToString();
     }

     &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; CustomerMetaData {

}&lt;/PRE&gt;
&lt;P&gt;The resulting display gets it right: the code now shows the correct field, and it distinguishes between David, Jinghao and Kevin Liu.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/photos/ricka/images/9132534/original.aspx" mce_src="http://blogs.msdn.com/photos/ricka/images/9132534/original.aspx"&gt; &lt;/P&gt;
&lt;P&gt;Special thanks to &lt;A href="http://blogs.msdn.com/davidebb/default.aspx" target=_blank mce_href="http://blogs.msdn.com/davidebb/default.aspx"&gt;David Ebbo&lt;/A&gt; for recommending the ToString() approach and &lt;A href="http://haacked.com/archive/2006/04/13/CallingDibsOnBlogging.aspx" target=_blank mce_href="http://haacked.com/archive/2006/04/13/CallingDibsOnBlogging.aspx"&gt;Phil Haack&lt;/A&gt; for granting me blog dibs.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9132537" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="Dynamic Data" scheme="http://blogs.msdn.com/rickandy/archive/tags/Dynamic+Data/default.aspx" /><category term="ASP.Net" scheme="http://blogs.msdn.com/rickandy/archive/tags/ASP.Net/default.aspx" /></entry><entry><title>How to create an updateable view with ADO Entity Framework and with LINQ to SQL</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2008/10/04/how-to-create-an-updateable-view-with-ado-entity-framework.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2008/10/04/how-to-create-an-updateable-view-with-ado-entity-framework.aspx</id><published>2008-10-04T05:07:00Z</published><updated>2008-10-04T05:07:00Z</updated><content type="html">&lt;P&gt;Creating an update-able view with&amp;nbsp; ADO Entity Framework (EF) or LINQ to SQL (L2S) is a fairly advanced topic and not directly associated with Dynamic Data. At the end of the article I have a sample console application to verify the modified L2S data model allows updates on a view. To create an update-able view, you must modify the wizard (or other tool) generated XML file (data model). Each time you generate a new data model (for example when the schema changes), you will need to reapply these steps. 
&lt;P&gt;ADO Entity Framework (EF) makes views Read Only via the &amp;lt;DefiningQuery&amp;gt; element. You make the data model view update-able by removing the &amp;lt;DefiningQuery&amp;gt; element and making a few minor changes. Note the example below is a very simple view on one table and includes the primary key. 
&lt;P&gt;This is what I did to make an update-able view for the AdventureWorksLT DB &lt;SPAN class=sqlkwd&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;
&lt;P&gt;CREATE&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;VIEW&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; [SalesLT]&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;[vAddr]&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;BR&gt;AS &lt;BR&gt;SELECT&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; AddressID&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;[AddressLine1]&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;[City]&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;[StateProvince]&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;[CountryRegion]&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;[PostalCode] &lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;FROM&lt;/FONT&gt;&lt;FONT size=+0&gt; [AdventureWorksLT2008]&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;[SalesLT]&lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;.&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;[Address]&lt;/FONT&gt;&lt;/SPAN&gt; 
&lt;P&gt;The next line shows this view is update-able (at least from T-SQL)&amp;nbsp;&amp;nbsp; 
&lt;P&gt;&lt;SPAN class=sqlkwd&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;UPDATE&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; vAddr &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;SET&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; PostalCode &lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;'54321'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;WHERE&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; addressID &lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; 11382 &lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;AND&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;BR&gt;StateProvince &lt;/FONT&gt;&lt;FONT color=#808080&gt;&lt;FONT color=#808080&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;'WA'&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;PRE class=coloredcode&gt;&lt;/FONT&gt;&lt;/SPAN&gt; (18 row(s) affected) &lt;/PRE&gt;
&lt;P&gt;Edit the EF SSDL, comment out the &amp;lt;DefiningQuery&amp;gt; , remove store: prefix from &lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;Schema&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;SalesLT&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=3&gt;and remove store:Name="vAddr" . The commented/changed code below&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;BR&gt;
&lt;P&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=#a31515&gt;&lt;FONT color=#a31515&gt;EntitySet&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;Name&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;Address&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;EntityType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;AdventureWorksLT2008Model.Store.Address&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;store:Type&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;Tables&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;Schema&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;SalesLT&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; /&amp;gt; &lt;BR&gt;&amp;lt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#a31515&gt;&lt;FONT color=#a31515&gt;EntitySet&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;Name&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;vAddr&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;EntityType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;AdventureWorksLT2008Model.Store.vAddr&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;store:Type&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;Views&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#ff0000&gt;&lt;FONT color=#ff0000&gt;Schema&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;SalesLT&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;"&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt; /&amp;gt; 
&lt;P&gt;&amp;lt;!--&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;FONT color=#008000&gt;&amp;lt;EntitySet Name="vAddr" EntityType="AdventureWorksLT2008Model.Store.vAddr" store:Type="Views" store:Schema="SalesLT" store:Name="vAddr"&amp;gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;--&amp;gt;&lt;BR&gt;&amp;lt;!--&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;FONT color=#008000&gt;&amp;lt;DefiningQuery&amp;gt;SELECT [vAddr].[AddressID] AS [AddressID], [vAddr].[AddressLine1] AS [AddressLine1], [vAddr].[City] AS [City], &lt;BR&gt;[vAddr].[StateProvince] AS [StateProvince], &lt;BR&gt;[vAddr].[CountryRegion] AS [CountryRegion], &lt;BR&gt;[vAddr].[PostalCode] AS [PostalCode] &lt;BR&gt;FROM [SalesLT].[vAddr] AS [vAddr]&amp;lt;/DefiningQuery&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;--&amp;gt; &lt;BR&gt;&amp;lt;!--&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;&lt;FONT color=#008000&gt;&amp;lt;/EntitySet&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;--&amp;gt; 
&lt;P&gt;&amp;lt;/&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#a31515&gt;&lt;FONT color=#a31515&gt;EntityContainer&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#000000&gt;
&lt;H1&gt;LINQ to SQL is the simplest.&lt;/H1&gt;Using the view above, &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#000000&gt;Simply change the following line in the wizard generated code to use&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT size=+0&gt;AutoSync = &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;AutoSync&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;&lt;FONT color=#000000&gt;.OnInsert &lt;/FONT&gt;&lt;FONT size=+0&gt;&lt;FONT color=#000000&gt;in lieu of &lt;FONT size=+0&gt;AutoSync=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af&gt;&lt;FONT color=#2b91af&gt;AutoSync&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000&gt;&lt;FONT size=+0&gt;.Always &lt;/FONT&gt;on the AddressID property.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;SPAN class=cmt&gt;&lt;BR&gt;
&lt;P&gt;&lt;FONT color=#008000&gt;&lt;FONT color=#008000&gt;// [Column(Storage="_AddressID", AutoSync=AutoSync.Always, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;BR&gt;[Column(Storage = &lt;/FONT&gt;&lt;FONT color=#a31515&gt;&lt;FONT color=#a31515&gt;"_AddressID"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;, AutoSync = AutoSync.OnInsert, DbType = &lt;/FONT&gt;&lt;FONT color=#a31515&gt;&lt;FONT color=#a31515&gt;"Int NOT NULL IDENTITY"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;, IsPrimaryKey = &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;, IsDbGenerated = &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;true&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt;)] &lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;public&lt;/FONT&gt;&lt;FONT size=+0&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;int&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=+0&gt; AddressID&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT color=#000000&gt;The following example shows how to test the view from a console application.&lt;/FONT&gt;&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Collections.Generic;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Linq;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Text;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Data.Linq;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Data.Linq.Mapping;

&lt;SPAN style="COLOR: blue"&gt;namespace &lt;/SPAN&gt;updateableView {

        &lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;T &lt;/SPAN&gt;{
            &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;LTDataContext &lt;/SPAN&gt;db;
            &lt;SPAN style="COLOR: green"&gt;//    readonly string con = "Data Source=bing0;Initial Catalog=AdventureWorksLT2008;Integrated Security=True";
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;readonly string &lt;/SPAN&gt;con = &lt;SPAN style="COLOR: #a31515"&gt;"Data Source=bing0;Initial Catalog=AdventureWorksLT2008;" &lt;/SPAN&gt;+
                                   &lt;SPAN style="COLOR: #a31515"&gt;"Persist Security Info=True;User ID=sa;Password=*(IU89iu"&lt;/SPAN&gt;;

            &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;T() {
                db = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;LTDataContext&lt;/SPAN&gt;(con);
            }

            &lt;SPAN style="COLOR: blue"&gt;public void &lt;/SPAN&gt;addAddr(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;city) {

                &lt;SPAN style="COLOR: #2b91af"&gt;vAddr &lt;/SPAN&gt;adr = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;vAddr&lt;/SPAN&gt;();
                adr.AddressLine1 = &lt;SPAN style="COLOR: #a31515"&gt;"1234 N St."&lt;/SPAN&gt;;
                adr.City = city;
                adr.PostalCode = &lt;SPAN style="COLOR: #a31515"&gt;"99966"&lt;/SPAN&gt;;
                adr.StateProvince = &lt;SPAN style="COLOR: #a31515"&gt;"Mt"&lt;/SPAN&gt;;
                adr.CountryRegion = &lt;SPAN style="COLOR: #a31515"&gt;"None"&lt;/SPAN&gt;;

                db.vAddrs.InsertOnSubmit(adr);
                db.SubmitChanges();
            }

            &lt;SPAN style="COLOR: blue"&gt;public void &lt;/SPAN&gt;tq(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;city) {

                &lt;SPAN style="COLOR: #2b91af"&gt;Table&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;vAddr&lt;/SPAN&gt;&amp;gt; addr = db.GetTable&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;vAddr&lt;/SPAN&gt;&amp;gt;();
                &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;q = &lt;SPAN style="COLOR: blue"&gt;from &lt;/SPAN&gt;c &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;addr
                        &lt;SPAN style="COLOR: blue"&gt;where &lt;/SPAN&gt;c.City == city
                        &lt;SPAN style="COLOR: blue"&gt;select &lt;/SPAN&gt;c;

                &lt;SPAN style="COLOR: blue"&gt;foreach &lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;cst &lt;SPAN style="COLOR: blue"&gt;in &lt;/SPAN&gt;q)
                    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"id = {0}, City = {1}"&lt;/SPAN&gt;, cst.AddressID, cst.City);
            }
        }

        &lt;SPAN style="COLOR: blue"&gt;class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Program &lt;/SPAN&gt;{
            &lt;SPAN style="COLOR: blue"&gt;static void &lt;/SPAN&gt;Main(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;[] args) {
                &lt;SPAN style="COLOR: #2b91af"&gt;T &lt;/SPAN&gt;tdb = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;T&lt;/SPAN&gt;();
                &lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;city = &lt;SPAN style="COLOR: #a31515"&gt;"GF"&lt;/SPAN&gt;;
                tdb.addAddr(city);
                tdb.tq(city);

            }
        }
    }

&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8976086" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="Dynamic Data" scheme="http://blogs.msdn.com/rickandy/archive/tags/Dynamic+Data/default.aspx" /><category term="ASP.Net" scheme="http://blogs.msdn.com/rickandy/archive/tags/ASP.Net/default.aspx" /></entry><entry><title>Tweaking the Filter Repeater</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/rickandy/archive/2008/09/25/tweaking-the-filter-repeater.aspx" /><id>http://blogs.msdn.com/rickandy/archive/2008/09/25/tweaking-the-filter-repeater.aspx</id><published>2008-09-25T22:58:00Z</published><updated>2008-09-25T22:58:00Z</updated><content type="html">&lt;P&gt;The default implementation of Dynamic Data provides a drop down list box for each foreign key and boolean field in a table. The drop down list allows you to filter the table with the value selected from the drop down list box. The figure below shows a view of the Product table from the AdventureWorksLT database. Several columns are not displayed because the &lt;A href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.scaffoldcolumnattribute.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.scaffoldcolumnattribute.aspx"&gt;scaffoldcolumnattribute&lt;/A&gt; was applied. 
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/photos/ricka0/images/8964060/original.aspx" mce_src="http://blogs.msdn.com/photos/ricka0/images/8964060/original.aspx"&gt; 
&lt;P&gt;The figure below shows the Product table again after Mountain Bikes is selected in the ProductCategory drop down list. Only products with product category Mountain Bikes are displayed. 
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/photos/ricka0/images/8964064/original.aspx" mce_src="http://blogs.msdn.com/photos/ricka0/images/8964064/original.aspx"&gt; &lt;/P&gt;
&lt;P&gt;The drop down list box is implemented in Dynamic Data by the FilterUserControl.ascx user control in the DynamicData\Content folder. While the filter user control is useful to filter a table when there are a relatively few foreign keys used as categories, it can be unmanageable on tables with hundreds or more foreign keys. For example, the CustomerAddress table of the AdventureWorksLT database has over 400 AddressID foreign keys, and each foreign key points to only one address of a customer (either the Main Office or the Shipping address). 
&lt;P&gt;When the foreign key field displayed by the filter user control is a very long string, the drop down list box can move off the browser window. This document will offer and approach to limit the width of the drop down list box. The figure below shows the ProductModelProductDescriptions from the AdventureWorksLT database. 
&lt;P&gt;In this blog I show how I like to establish a maximum number of entries in the filter repeater and how to set the maximum width. 
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/photos/ricka0/images/8964065/original.aspx" mce_src="http://blogs.msdn.com/photos/ricka0/images/8964065/original.aspx"&gt; 
&lt;H3&gt;Modifying the filter user control to limit number of entries&lt;/H3&gt;
&lt;P&gt;&lt;STRONG&gt;Editing the filter user control&lt;BR&gt;&lt;BR&gt;&lt;/STRONG&gt;1. Add a key element to the &lt;A href="http://msdn.microsoft.com/en-us/library/ms228154.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms228154.aspx"&gt;appSettings&lt;/A&gt; Element in the web.config file that will set an upper bound to the number of foreign key entries that will be displayed. The following example sets the upper bound to 55.&amp;nbsp; &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;appSettings&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;add &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;FilterUC_FK_limit&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;955&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;add &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;FilterUC_Char_limit&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;50&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;appSettings&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;1 Add a text label to the the filter user control in the FilterUserControl.ascx file found in the DynamicData\Content folder. The following example shows the completed markup. &lt;PRE class=code&gt;&lt;SPAN style="BACKGROUND: #ffee62"&gt;&amp;lt;%&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;@ &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Control &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Language&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="C#" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;CodeFile&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="FilterUserControl.ascx.cs" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Inherits&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="FilterUserControl" &lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #ffee62"&gt;%&amp;gt;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Label &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="LBL1" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="server" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="Label" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ForeColor&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;= "Brown" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Font-Bold&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="true" /&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DropDownList &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="DropDownList1" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="server" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;AutoPostBack&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="true" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;EnableViewState&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="true" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="droplist"&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ListItem &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="All" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="" /&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DropDownList&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;3. Add a string property to the FilterUserControl. For example, add a property with the name LBL_Txt that will be used to set the label we added to the FilterUserControl.aspx file in a previous step. 
&lt;P&gt;4. Add the Page_PreRender method in the FilterUserControl code behind file and set the label text. For example, set the label text with the LBL_Txt property created in the previous step. 
&lt;P&gt;5. Modify the Page_Init method in the FilterUserControl code behind file to limit the number of foreign keys displayed. The FilterUC_FK_limit application setting created in the first step will be used to set the maximum number of entries in the drop down list box. The following example shows the completed FilterUserControl code behind file. 
&lt;P&gt;&lt;B&gt;Visual Basic&lt;/B&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Imports &lt;/SPAN&gt;System.Web.DynamicData

&lt;SPAN style="COLOR: blue"&gt;Partial Class &lt;/SPAN&gt;FilterUserControl
    &lt;SPAN style="COLOR: blue"&gt;Inherits &lt;/SPAN&gt;System.Web.DynamicData.FilterUserControlBase
    &lt;SPAN style="COLOR: green"&gt;'
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Public &lt;/SPAN&gt;LBL_Txt &lt;SPAN style="COLOR: blue"&gt;As String
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Public Overrides ReadOnly Property &lt;/SPAN&gt;SelectedValue &lt;SPAN style="COLOR: blue"&gt;As String
        Get
            Return &lt;/SPAN&gt;DropDownList1.SelectedValue
        &lt;SPAN style="COLOR: blue"&gt;End Get
    End Property
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Public Event &lt;/SPAN&gt;SelectedIndexChanged &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;EventHandler
    &lt;SPAN style="COLOR: green"&gt;'
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Protected Sub &lt;/SPAN&gt;Page_Init(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;EventArgs)
        &lt;SPAN style="COLOR: green"&gt;'
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;Page.IsPostBack &lt;SPAN style="COLOR: blue"&gt;Then
            Return
        End If
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'
        &lt;/SPAN&gt;PopulateListControl(DropDownList1)
        &lt;SPAN style="COLOR: green"&gt;'
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;maxCnt &lt;SPAN style="COLOR: blue"&gt;As Integer &lt;/SPAN&gt;= Convert.ToInt32(ConfigurationManager.AppSettings(&lt;SPAN style="COLOR: #a31515"&gt;"FilterUC_FK_limit"&lt;/SPAN&gt;))
        &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;(DropDownList1.Items.Count &amp;gt; maxCnt) &lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;DropDownList1.Visible = &lt;SPAN style="COLOR: blue"&gt;False
            &lt;/SPAN&gt;LBL1.Visible = &lt;SPAN style="COLOR: blue"&gt;False
        End If
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;If Not String&lt;/SPAN&gt;.IsNullOrEmpty(InitialValue) &lt;SPAN style="COLOR: blue"&gt;Then
            &lt;/SPAN&gt;DropDownList1.SelectedValue = InitialValue
        &lt;SPAN style="COLOR: blue"&gt;End If
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;End Sub
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;'
    '
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;Protected Sub &lt;/SPAN&gt;Page_PreRender(&lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;sender &lt;SPAN style="COLOR: blue"&gt;As Object&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;ByVal &lt;/SPAN&gt;e &lt;SPAN style="COLOR: blue"&gt;As &lt;/SPAN&gt;System.EventArgs) &lt;SPAN style="COLOR: blue"&gt;Handles Me&lt;/SPAN&gt;.PreRender
        LBL1.Text = LBL_Txt
    &lt;SPAN style="COLOR: blue"&gt;End Sub
End Class
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;&lt;B&gt;C#&lt;/B&gt;&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Data;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Configuration;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Collections;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Collections.Specialized;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Linq;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Web;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Web.Security;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Web.UI;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Web.UI.WebControls;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Web.UI.WebControls.WebParts;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Web.UI.HtmlControls;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Xml.Linq;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Web.DynamicData;

&lt;SPAN style="COLOR: blue"&gt;public partial class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FilterUserControl &lt;/SPAN&gt;: System.Web.DynamicData.&lt;SPAN style="COLOR: #2b91af"&gt;FilterUserControlBase &lt;/SPAN&gt;{

    &lt;SPAN style="COLOR: blue"&gt;public string &lt;/SPAN&gt;LBL_Txt { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;; }

    &lt;SPAN style="COLOR: blue"&gt;public event &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EventHandler &lt;/SPAN&gt;SelectedIndexChanged {
        &lt;SPAN style="COLOR: blue"&gt;add &lt;/SPAN&gt;{
            DropDownList1.SelectedIndexChanged += &lt;SPAN style="COLOR: blue"&gt;value&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: blue"&gt;remove &lt;/SPAN&gt;{
            DropDownList1.SelectedIndexChanged -= &lt;SPAN style="COLOR: blue"&gt;value&lt;/SPAN&gt;;
        }
    }

    &lt;SPAN style="COLOR: blue"&gt;public override string &lt;/SPAN&gt;SelectedValue {
        &lt;SPAN style="COLOR: blue"&gt;get &lt;/SPAN&gt;{
            &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;DropDownList1.SelectedValue;
        }
    }

    &lt;SPAN style="COLOR: blue"&gt;protected void &lt;/SPAN&gt;Page_PreRender(&lt;SPAN style="COLOR: blue"&gt;object &lt;/SPAN&gt;sender, &lt;SPAN style="COLOR: #2b91af"&gt;EventArgs &lt;/SPAN&gt;e) {
        LBL1.Text = LBL_Txt;
    }

    &lt;SPAN style="COLOR: blue"&gt;protected void &lt;/SPAN&gt;Page_Init(&lt;SPAN style="COLOR: blue"&gt;object &lt;/SPAN&gt;sender, &lt;SPAN style="COLOR: #2b91af"&gt;EventArgs &lt;/SPAN&gt;e) {

        &lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(Page.IsPostBack)
            &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;; PopulateListControl(DropDownList1);

        &lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;maxCnt = &lt;SPAN style="COLOR: #2b91af"&gt;Convert&lt;/SPAN&gt;.ToInt32(&lt;SPAN style="COLOR: #2b91af"&gt;ConfigurationManager&lt;/SPAN&gt;.AppSettings[&lt;SPAN style="COLOR: #a31515"&gt;"FilterUC_FK_limit"&lt;/SPAN&gt;]); 
        &lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(DropDownList1.Items.Count &amp;gt; maxCnt) {
            DropDownList1.Visible = &lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;;
            LBL1.Visible = &lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;;
        }

        &lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(!&lt;SPAN style="COLOR: #2b91af"&gt;String&lt;/SPAN&gt;.IsNullOrEmpty(InitialValue))
            DropDownList1.SelectedValue = InitialValue;
    }
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;&lt;BR&gt;&amp;nbsp;&lt;/P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;5. Remove the original filter label from the page template (list.aspx and listDetails.aspx) and initialize the new label. The original markup is shown below.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FilterRepeater &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="FilterRepeater" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="server"&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ItemTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
       &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Label &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="server" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;='&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #ffee62"&gt;&amp;lt;%&lt;/SPAN&gt;# Eval("DisplayName") &lt;SPAN style="BACKGROUND: #ffee62"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;' &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;AssociatedControlID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="DynamicFilter$DropDownList1" /&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DynamicFilter &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="server" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="DynamicFilter" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;OnSelectedIndexChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="OnFilterSelectedIndexChanged" /&amp;gt;
     &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ItemTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
     &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FooterTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;br &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;/&amp;gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;br &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;/&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FooterTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
 &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FilterRepeater&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;The replacement markup is shown below.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ItemTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DynamicFilter &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="server" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="DynamicFilter" &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;LBL_Txt&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;='&lt;/SPAN&gt;&lt;SPAN style="BACKGROUND: #ffee62"&gt;&amp;lt;%&lt;/SPAN&gt;# Eval("DisplayName") &lt;SPAN style="BACKGROUND: #ffee62"&gt;%&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;'
                      &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;OnSelectedIndexChanged&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;="OnFilterSelectedIndexChanged" /&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ItemTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H5&gt;Part II:&amp;nbsp; Limiting the width of the filter user control Part II: &lt;/H5&gt;
&lt;P&gt;To limit the width of the drop down list box, the elements of the list box will be truncated at the maximum allowed character width.Editing the filter user control for maximum characters1. Add a key element to the &lt;A href="http://msdn.microsoft.com/en-us/library/ms228154.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms228154.aspx"&gt;appSettings&lt;/A&gt; Element in the web.config file that will set an upper bound on the number of characters that will be copied to each element of the drop downn list. The key with value FilterUC_Char_limit sets the maximum number of characters to 50. &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;appSettings&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;add &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;FilterUC_FK_limit&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;955&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;add &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;FilterUC_Char_limit&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;50&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;appSettings&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;2. Modify the Page_Init method in the FilterUserControl code behind file to limit the number of characters to be copied to the drop down list box. The following example shows how to limit the number of characters. 
&lt;P&gt;&lt;B&gt;C#&lt;/B&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;maxLen = &lt;SPAN style="COLOR: #2b91af"&gt;Convert&lt;/SPAN&gt;.ToInt32(&lt;SPAN style="COLOR: #2b91af"&gt;ConfigurationManager&lt;/SPAN&gt;.AppSettings[&lt;SPAN style="COLOR: #a31515"&gt;"FilterUC_Char_limit"&lt;/SPAN&gt;]);

&lt;SPAN style="COLOR: blue"&gt;for &lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;i = 0; i &amp;lt; DropDownList1.Items.Count; i++) {
&lt;SPAN style="COLOR: blue"&gt;   string &lt;/SPAN&gt;s = DropDownList1.Items[i].Text;

&lt;SPAN style="COLOR: blue"&gt;   if &lt;/SPAN&gt;(s.Length &amp;gt; maxLen) {
      s = s.Substring(0, maxLen - 1);
      s += &lt;SPAN style="COLOR: #a31515"&gt;" ... (see Details for full)"&lt;/SPAN&gt;;
      DropDownList1.Items[i].Text = s;
   }
}&lt;/PRE&gt;
&lt;P&gt;&lt;B&gt;Visual Basic&lt;/B&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;maxLen &lt;SPAN style="COLOR: blue"&gt;As Integer &lt;/SPAN&gt;= Convert.ToInt32(ConfigurationManager.AppSettings(&lt;SPAN style="COLOR: #a31515"&gt;"FilterUC_Char_limit"&lt;/SPAN&gt;))
   &lt;SPAN style="COLOR: blue"&gt;For &lt;/SPAN&gt;i &lt;SPAN style="COLOR: blue"&gt;As Integer &lt;/SPAN&gt;= 0 &lt;SPAN style="COLOR: blue"&gt;To &lt;/SPAN&gt;DropDownList1.Items.Count - 1

       &lt;SPAN style="COLOR: blue"&gt;Dim &lt;/SPAN&gt;s &lt;SPAN style="COLOR: blue"&gt;As String &lt;/SPAN&gt;= DropDownList1.Items(i).Text

       &lt;SPAN style="COLOR: blue"&gt;If &lt;/SPAN&gt;s.Length &amp;gt; maxLen &lt;SPAN style="COLOR: blue"&gt;Then
           &lt;/SPAN&gt;s = s.Substring(0, maxLen - 1)
           s += &lt;SPAN style="COLOR: #a31515"&gt;" ... (see Details for full)"
           &lt;/SPAN&gt;DropDownList1.Items(i).Text = s
       &lt;SPAN style="COLOR: blue"&gt;End If
   Next&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;The figure below shows the results with the ProductModelProductDescription table. 
&lt;P&gt;&lt;IMG src="http://blogs.msdn.com/photos/ricka0/images/8964062/original.aspx" mce_src="http://blogs.msdn.com/photos/ricka0/images/8964062/original.aspx"&gt; &lt;/P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8965486" width="1" height="1"&gt;</content><author><name>ricka0</name><uri>http://blogs.msdn.com/members/ricka0.aspx</uri></author><category term="Dynamic Data" scheme="http://blogs.msdn.com/rickandy/archive/tags/Dynamic+Data/default.aspx" /><category term="ASP.Net" scheme="http://blogs.msdn.com/rickandy/archive/tags/ASP.Net/default.aspx" /></entry></feed>