Saturday, January 3, 2009

Creating a .NET Web Service

Introduction

Microsoft .NET marketing has created a huge hype about its Web Services. This is the first of two articles on Web Services. Here we will create a .NET Web Service using C#. We will look closely at the Discovery protocol, UDDI, and the future of the Web Services. In the next article, we will concentrate on consuming existing Web Services on multiple platforms (i.e., Web, WAP-enabled mobile phones, and windows applications).

Why do we need Web Services?

After buying something over the Internet, you may have wondered about the delivery status. Calling the delivery company consumes your time, and it's also not a value-added activity for the delivery company. To eliminate this scenario the delivery company needs to expose the delivery information without compromising its security. Enterprise security architecture can be very sophisticated. What if we can just use port 80 (the Web server port) and expose the information through the Web server? Still, we have to build a whole new Web application to extract data from the core business applications. This will cost the delivery company money. All the company wants is to expose the delivery status and concentrate on its core business. This is where Web Services come in.

What is a Web Service?

Web Services are a very general model for building applications and can be implemented for any operation system that supports communication over the Internet. Web Services use the best of component-based development and the Web. Component-base object models like Distributed Component Object Model (DCOM), Remote Method Invocation (RMI), and Internet Inter-Orb Protocol (IIOP) have been around for some time. Unfortunately all these models depend on an object-model-specific protocol. Web Services extend these models a bit further to communicate with the Simple Object Access Protocol (SOAP) and Extensible Markup Language (XML) to eradicate the object-model-specific protocol barrier (see Figure 1).

Web Services basically uses Hypertext Transfer Protocol (HTTP) and SOAP to make business data available on the Web. It exposes the business objects (COM objects, Java Beans, etc.) to SOAP calls over HTTP and executes remote function calls. The Web Service consumers are able to invoke method calls on remote objects by using SOAP and HTTP over the Web.

http://www.15seconds.com/graphics/issue/010427_1.gif

Figure 1. SOAP calls are remote function calls that invoke method executions on Web Service components at Location B. The output is rendered as XML and passed back to the user at Location A.

How is the user at Location A aware of the semantics of the Web Service at Location B? This question is answered by conforming to a common standard. Service Description Language (SDL), SOAP Contract Language (SCL) and Network Accessible Specification Language (NASSL) are some XML-like languages built for this purpose. However, IBM and Microsoft recently agreed on the Web Service Description Language (WSDL) as the Web Service standard.

The structure of the Web Service components is exposed using this Web Service Description Language. WSDL 1.1 is a XML document describing the attributes and interfaces of the Web Service. The new specification is available at msdn.microsoft.com/xml/general/wsdl.asp.

The task ahead

The best way to learn about Web Services is to create one. We all are familiar with stock quote services. The NASDAQ, Dow Jones, and Australian Stock Exchange are famous examples. All of them provide an interface to enter a company code and receive the latest stock price. We will try to replicate the same functionality.

The input parameters for our securities Web service will be a company code. The Web service will extract the price feed by executing middle-tier business logic functions. The business logic functions are kept to a bare minimum to concentrate on the Web service features.

Tools to create a Web Service

The core software component to implement this application will be MS .NET Framework SDK, which is currently in beta. You can download a version from Microsoft. I used Windows 2000 Advance Server on a Pentium III with 300 MB of RAM.

The preferred Integration Development Environment (IDE) to create Web Services is Visual Studio .NET. However, you can easily use any text editor (WordPad, Notepad, Visual Studio 6.0) to create a Web Service file.

I assume you are familiar with the following concepts:

* Basic knowledge of .NET platform
* Basic knowledge of C#
* Basic knowledge of object-oriented concepts

Creating a Web Service

We are going to use C# to create a Web Service called "SecurityWebService." A Web Service file will have an .ASMX file extension. (as opposed to an .ASPX file extension of a ASP.NET file). The first line of the file will look like

<%@ WebService Language="C#" class="SecurityWebService" %>

This line will instruct the compiler to run on Web Service mode and the name of the C# class. We also need to access the Web Service namespace. It is also a good practice to add a reference to the System namespace.

using System;
using System.Web.Services;

The SecurityWebService class should inherit the functionality of the Web Services class. Therefore, we put the following line of code:

public class SecurityWebService : WebService

Now we can use our object-oriented programming skills to build a class. C# classes are very similar to C++ or Java classes. It will be a walk in the park to create a C# class for anyone with either language-coding skills.

Dot-net Web Services are intelligent enough to cast basic data types. Therefore, if we return "int," "float," or "string" data types, it can convert them to standard XML output. Unfortunately, in most cases we need get a collection of data regarding a single entity. Let's take an example.

Our SecurityWebService stock quotes service requires the user to enter a company code, and it will deliver the full company name and the current stock price. Therefore, we have three pieces of information for a single company:

1. Company code (data type - string)
2. Company name (data type - string)
3. Price (data type - Double)

We need to extract all this data when we are referring to a single stock quote. There are several ways of doing this. The best way could be to bundle them in an enumerated data type. We can use "structs" in C# to do this, which is very similar to C++ structs.

public struct SecurityInfo
{
public string Code;
public string CompanyName;
public double Price;
}

Now we have all the building blocks to create our Web Service. Therefore, our code will look like.


<%@ WebService Language="C#" class="SecurityWebService" %>

using System;
using System.Web.Services;

public struct SecurityInfo
{
public string Code;
public string CompanyName;
public double Price;
}

public class SecurityWebService : WebService
{
private SecurityInfo Security;

public SecurityWebService()
{
Security.Code = "";
Security.CompanyName = "";
Security.Price = 0;
}

private void AssignValues(string Code)
{
// This is where you use your business components.
// Method calls on Business components are used to populate the data.
// For demonstration purposes, I will add a string to the Code and
// use a random number generator to create the price feed.

Security.Code = Code;
Security.CompanyName = Code + " Pty Ltd";
Random RandomNumber = new System.Random();
Security.Price = double.Parse(new System.Random(RandomNumber.Next(1,10)).NextDouble().ToString("##.##"));
}


[WebMethod(Description="This method call will get the company name and the price for a given security code.",EnableSession=false)]
public SecurityInfo GetSecurityInfo(string Code)
{
AssignValues(Code);
SecurityInfo SecurityDetails = new SecurityInfo();
SecurityDetails.Code = Security.Code;
SecurityDetails.CompanyName = Security.CompanyName;
SecurityDetails.Price = Security.Price;
return SecurityDetails;
}

}

Remember, this Web Service can be accessed through HTTP for any use. We may be referring to sensitive business data in the code and wouldn't want it to fall into the wrong hands. The solution is to protect the business logic function and only have access to the presentation functions. This is achieved by using the keyword "[Web Method]" in C#. Let's look at the function headers of our code.

[WebMethod(Description="This......",EnableSession=false)]
public SecurityInfo GetSecurityInfo(string Code)

This function is exposed to the public. The "description" tag can be used to describe the Web Service functionality. Since we will not be storing any session data, we will disable the session state.

private void AssignValues(string Code)

This is a business logic function that should not be publicly available. We do not want our sensitive business information publicly available on the Web. (Note:- Even if you change the "private" keyword to "public," it will still not be publicly available. You guessed it, the keyword "[Web Method]" is not used.)

We can use the business logic in this function to get the newest stock price quote. For the purpose of this article I have added some text to the company code to create the company name. The price value is generated using a random number generator.

We may save this file as "SampleService.asmx" under an Internet Information Service (IIS)-controlled directory. I have saved it under a virtual directory called "/work/aspx." I'll bring it up on a Web browser.

This is a Web page rendered by the .NET Framework. We did not create this page. (The page is generated automatically by the system. I did not write any code to render it on the browser. This graphic is a by-product of the previous code.) This ready-to-use functionality is quite adequate for a simple Web Service. The presentation of this page can be changed very easily by using ASP.NET pagelets and config.web files. A very good example can be found at http://www.ibuyspy.com/store/InstantOrder.asmx.

Notice a link to "SDL Contract." (Even if we are using WSDL, .NET Beta still refers to SDL. Hopefully this will be rectified in the next version). This is the description of the Web Service to create a proxy object. (I will explain this in the next article.) This basically gives an overview of the Web Service and it's public interface. If you look closely, you will only see the "Web-only" methods being illustrated. All the private functions and attributes are not described in the SDL contract. The SDL contract for the SecurityWebService can be found in Appendix A.

# view demo of SecurityWebService

How do we use a Web Service?

Now we can use this Web Service. Let's enter some values to get a bogus price feed.

By clicking the Invoke button a new window will appear with the following XML document

This is how the Web Service releases information. We need to write clients to extract the information from the XML document. Theses clients could be

1. A Web page
2. A console / Windows application
3. A Wireless Markup Language (WML) / WMLScript to interact with mobile phones
4. A Palm / Win CE application to use on Personal Digital Assistants (PDAs).

I will explain this process in the next article.

You can also call the Web Service directly using the HTTP GET method. In this case we will not be going through the above Web page and clicking the Invoke button. The syntax for directly calling the Web Service using HTTP GET is

http://server/webServiceName.asmx/functionName?parameter=parameterValue

Therefore, the call for our Web Service will be

http://localhost/work/aspx/SampleService.asmx/GetSecurityInfo?Code=IBM

This will produce the same result as clicking the Invoke button.

Now we know how to create a Web Service and use it. But the work is half done. How will our clients find our Web Service? Is there any way to search for our Web Service on the Internet? Is there a Web crawler or a Yahoo search engine for Web Services? In order to answer these questions we need to create a "discovery" file for our Web Service.

Creating a Discovery file

Web Service discovery is the process of locating and interrogating Web Service descriptions, which is a preliminary step for accessing a Web Service. It is through the discovery process that Web Service clients learn that a Web Service exists, what its capabilities are, and how to properly interact with it. Discovery file is a XML document with a .DISCO extension. It is not compulsory to create a discovery file for each Web Service. Here is a sample discovery file for our securities Web Service.






We can name this file "SampleService.disco" and save it to the same directory as the Web Service. If we are creating any other Web Services under the "/work/aspx" directory, it is wise to enable "dynamic discovery." Dynamic discovery will scan for all the *.DISCO files in all the subdirectories of "/work/aspx" automatically.





An example of an active discovery file can be found at http://services3.xmethods.net/dotnet/default.disco. By analyzing the discovery file we can find where the Web Services reside in the system. Unfortunately both these methods require you to know the exact URL of the discovery file. If we cannot find the discovery file, we will not be able to locate the Web Services. Universal Description, Discovery, and Integration (UDDI) describes mechanisms to advertise existing Web Services. This technology is still at the infant stage. UDDI is an open, Internet-based specification designed to be the building block that will enable businesses to quickly, easily, and dynamically find and transact business with one another using their preferred applications. A reference site for UDDI is http://uddi.microsoft.com.

There have been a lot of Web Services written by developers. www.xmethods.com is one of the sites that has an index of Web Services. Some developers are building WSDL search engines to find Web Services on the Web.

Deploying a Web Service

Deploying the Web Services from development to staging or production is very simple. Similar to ASP.NET applications, just copy the .ASMX file and the .DISCO files to the appropriate directories, and you are in business.

The future of the Web Services

The future looks bright for the Web Service technology. Microsoft is not alone in the race for Web Service technology. Sun and IBM are very interested. There are SOAP toolkits available for Apache and Java Web servers. I believe Web Services needs a bit of work, especially the Web Service discovery process. It is still very primitive.

On a positive note, Web Services have the potential to introduce new concepts to the Web. One I refer to as "pay per view" architecture. Similar to pay-TV, we can build Web sites that can generate revenue for each request a user sends (as opposed to a flat, monthly subscription). In order to get some data, we can sometimes pay a small fee. Commercially this could be handy for a lot of people.

Examples

* Online newspaper sites can publish a 10-year-old article with a $2 "pay per view" structure.
* Stock market portals can itemize every user portfolio for every single stock quote and build pricing and discount structures.

And the list goes on ...

On a very optimistic note, Web Services can be described as the "plug and play" building blocks of enterprise Business to Business (B2B) Web solutions.

Appendix A



xmlns="urn:schemas-xmlsoap-org:sdl.2000-01-25">








This method call will get the company name and the price for a given security code.














This method call will get the company name and the price for a given security code.












This method call will get the company name and the price for a given security code.



elementFormDefault="qualified" xmlns="http://www.w3.org/1999/XMLSchema">























ASP.NET OnClientClick Property

Definition and Usage

The OnClientClick property is used to sets a client side script to be run when the Button control is clicked.

The script specified in this property is run by the Button's event "OnClick" in addition to the predefined script.
Syntax




Attribute Description
func Client side script to be run when button is clicked

Example

The following example runs two scripts when the Button control is clicked:







Text="Click Me" runat="server" />







OnClientClick property for developers (in 2.0

If we wanted to fire up a client-side code on 'onclick' of a Button control, currently in ASP.NET 1.0 and 1.1 by adding similar to the following code would helps!

protected override void OnPreRender(EventArgs e)
{

btnClick.Attributes.Add("onclick", "return confirm('Are you the people from Planet Earth?');");

}

Or we could also add the similar code in Page_Load!!

void Page_Load(object sender, EventArgs e)
{

btnClick.Attributes.Add("onclick", "return confirm('Are you the people from Planet Earth?');");

}


Just to find how Script Engine is generating (XX.Attributes.Add to the client side code) or Spitting the code to Client browser, I have added the code in OnPreRender and Page_Load, Guess what?? It's intelligent enfough and showed only once on client browser :)

OK.. Let's come to the main streem...to have onClick to the button, we have to write some code in 1.0 and 1.1 as shown above, there is not direct method for us to do it! But in 2.0, by using of OnClientClick attribute on Button control, we could generate onClick event on Client-Side!

The example would be as shown below:



Do you liked it!! Exited!! Wanted to use this!! Holde your breath and wait for 2.0 :)

By the way in future we might expect server side functions for messagebox/input on client side... For info see MessageBox and InputBox Support for ASP.NET from Code Behind @ labs

ScottGu's : ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas

This page lists some of the more popular “ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas” posts I’ve done. My goal is to add new posts to the series regularly going forward – so bookmark this page for updates, or subscribe to my blog via this RSS feed.

To learn more about ASP.NET, also make sure to watch all of the great “ASP.NET: How Do I?” videos (each week a new video is posted). You can also browse a large listing of other ASP.NET 2.0 books here.
Visual Studio 2005

* Tip/Trick: Optimizing ASP.NET 2.0 Web Project Build Performance with VS 2005
* Common Gotcha: Slow VS 2005 Web Site Build Performance Because of “Dueling Assembly References”
* Common Gotcha: Public Hotfix available for Slow Debugging Problems
* Tip/Trick: Changing the default browser used in VS 2005 and Visual Web Developer
* Tip/Trick: Creating Packaged ASP.NET Setup Programs with VS 2005
* Resource: VS 2005 Web Application Project Tutorials
* Recipe: Using VS 2005 Web Deployment Projects
* Tip/Trick: Custom formatting HTML in Visual Web Developer and Visual Studio 2005
* Tip/Trick: Fast HTML Editor Navigation within VS 2005
* Tip/Trick: How to Run a Root “/” Site with the Local Web Server using VS 2005 SP1
* Tip/Trick: Creating Re-Usable Project and Item Templates with VS 2005
* Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option
* Tip/Trick: Spell Checker Plug-in for VS 2005 for ASP.NET and HTML Pages
* Tip/Trick: Using IIS7 on Vista with VS 2005
* Gotcha: Fixing Error with VS 2005 SP1 Beta and older Web Application Project Templates

UI

* Tip/Trick: Enabling URL Rewriting with ASP.NET
* Tip/Trick: Using Server Side Comments with ASP.NET 2.0
* Tip/Trick: Use the ASP.NET 2.0 CSS Control Adapters for CSS friendly HTML output
* Tip/Trick: How to Register User Controls and Custom Controls in Web.config
* Recipe: Dynamic Site Layout and Style Personalization with ASP.NET
* Tip/Trick: Advanced Article on ASP.NET 2.0 Master Pages

AJAX

* Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX
* Tip/Trick: Cool UI Templating Technique to use with ASP.NET AJAX for non-UpdatePanel scenarios
* Links: ASP.NET AJAX and ASP.NET AJAX Control Toolkit Articles
* Gotcha: Lost HTML Intellisense within ASP.NET AJAX Controls
* Gotcha: Don't use with ASP.NET AJAX
* Tip/Trick: UpdateProgress Control and AJAX Activity Image Animations
* Tip/Trick: Nikhil's WebDevHelper Utility and ASP.NET AJAX Support

Data

* Tip/Trick: How to Upload a .SQL file to a Hoster and Execute it to Deploy a Database
* Tip/Trick: Deploying a SQL Database to a Remote Hoster Environment
* Tip/Trick: Online Database Schema Samples Library
* Recipe: Great ASP.NET 2.0 Data Tutorials
* Recipe ASP.NET 2.0 RSS Tool-Kit
* Recipe: Paging through lots of data efficiently (and in an Ajax way) with ASP.NET 2.0
* Recipe: Efficient Data Paging with the ASP.NET 2.0 DataList Control and ObjectDataSource
* Tip/Trick: ListControl.AppendDataBoundItems Property in ASP.NET 2.0

Security

* Resource: ASP.NET 2.0 Membership, Roles, Forms Authentication, and Security Resources
* Recipe: Enabling Windows Authentication within an Intranet ASP.NET Web application
* Recipe: Implementing Role Based Security with ASP.NET using Windows Authentication and SQL Server
* Recipe: Configuring ASP.NET 2.0 Application Services to use SQL Server 2000 or SQL Server 2005
* Tip/Trick: Integrating ASP.NET Security with Classic ASP and non-ASP.NET URLs
* Gotcha: Always set the "applicationName" property when configuring ASP.NET 2.0 Membership and other Providers
* Common Gotcha: Don't forget to when adding providers
* Tip/Trick: Source/Documentation for Simple ASP.NET 2.0 SQL Providers Published
* Tip/Trick: Guard Against SQL Injection Attacks
* Tip/Trick: Gathering Custom User Registration Information
* Recipe: How to add a Login, Roles and Profile system to an ASP.NET 2.0 app in only 24 lines of code
* Gotcha: Authorization with the built-in VS 2005 Web Server (aka Cassini)
* Gotcha: Forms Authentication timeout default changed between ASP.NET 1.1 -> ASP.NET 2.0
* Tip/Trick: How To Share Authentication Cookies across ASP.NET V1.1 and ASP.NET V2.0 Applications
* Tip/Trick: Enabling SSL on IIS 7.0 using Self Signed Certificates

Deployment

* Gotcha: Don’t run production ASP.NET Applications with debug=”true” enabled
* Tip/Trick: Automating Dev, QA, Production Web.Config Settings with VS 2005
* Tip/Trick: Creating Packaged ASP.NET Setup Programs with VS 2005
* Tip/Trick: Patterns and Practices Guidance Explorer for .NET and ASP.NET
* Tip/Trick: App_Offline.htm and working around the "IE Friendly Errors" feature
* Tip/Trick: Show Detailed Error Messages to Developers (and only to Developers)
* Tip/Trick: Logging ASP.NET Application Shutdown Events

Performance

* Tip/Trick: Implement "Donut Caching" with the ASP.NET 2.0 Output Cache Substitution Feature
* Tip/Trick: Disk Based Output Caching Feature Now Available for ASP.NET 2.0
* Tip/Trick: Cache Manager

.NET 3.5 and VS 2008

* VS 2008 Multi-Targeting Support
* VS 2008 JavaScript Intellisense
* VS 2008 JavaScript Debugging
* VS 2008 Code Editing Improvements
* VS 2008 Nested Master Page Support
* VS 2008 Web Designer and CSS Improvements
* VS 2008 Vertical Split View Support
* VS 2008 ASP.NET AJAX Control Extenders
* ASP.NET ListView Control (Part 1: Building a Product Listing Page with Pure CSS)
* ASP.NET AJAX in .NET 3.5 and VS 2008

LINQ and .NET 3.5

* LINQ to SQL (Part 1 - Overview)
* LINQ to SQL (Part 2 - Defining our Data Model Classes)
* LINQ to SQL (Part 3 - Querying our Database)
* LINQ to SQL (Part 4 - Updating our Database)
* LINQ to SQL (Part 5 - Binding UI using the asp:linqdatasource)
* LINQ to SQL (Part 6 - Retrieving data using stored procedures)
* LINQ to SQL (Part 7 - Updating our database using stored procedures)
* LINQ to SQL (Part 8 - Executing Custom SQL Expressions)
* LINQ to SQL (Part 9 - Using a Custom LINQ Expression with the control)
* LINQ to XML (How to Build a Custom RSS Reader with it)
* New Language Feature: Automatic Properties, Object Initializer and Collection Initializers
* New Language Feature: Extension Methods
* New Language Feature: Lambda Expressions
* New Language Feature: Query Syntax
* New Language Feature: Anonymous Types
* Recipe: Tagging Data using LINQ
* Null Coalescing Operator and using it with LINQ

Silverlight

* My Silverlight Overview Post
* My "Lap Around Silverlight" talk from TechEd
* Building Silverlight Applications using .NET
* Tip/Trick: Supporting Full Screen Mode with Silverlight
* VS 2008 JavaScript Intellisense for Silverlight

Miscellaneous

* Resource: Credit Card Payment Processing with ASP.NET
* Tip/Trick: List Running ASP.NET Worker Processes and Kill/Restart them from the command-line

Published Monday, July 31, 2006 11:00 PM by ScottGu
Filed under: ASP.NET, Visual Studio, Tips and Tricks
Comments
# My ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas "Highlights Page"
Wednesday, August 02, 2006 2:52 AM by ScottGu's Blog

Several people have sent me email lately asking for a suggested short-list of my best/favorite blog posts
# If you work with ASP.NET 2.0 you should be reading Scott Guthrie's blog
Wednesday, August 02, 2006 4:03 AM by the roarty blog

You should be reading Scott Guthrie already if you are doing ASP.NET 2.0 work but perhaps you aren't...
# ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, August 02, 2006 7:35 AM by My Blog
# ASP.NET 2.0 Tips and Tricks.... Setting up Subversion at home... Centrino
Wednesday, August 02, 2006 9:46 AM by Andrew Connell [MVP MCMS]
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, August 02, 2006 10:55 AM by burlistic
Nice post.. I have only just come across your blog and what I have read so fair has been very helpful. This list is certainly worth a bookmark. Thanks, BuR
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, August 02, 2006 5:21 PM by Sue Googe
This is awesome! It save us time digging around your blog :-) Keep up with the good work!
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, August 02, 2006 5:56 PM by 压力变送器
Nice post.. I have only just come across your blog and what I have read so fair has been very helpful.
# ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, August 03, 2006 12:47 AM by It's Way Too Early For This

This is a great resource for anyone who is developing in ASP.NET 2.0 http://weblogs.asp.net/scottgu/pages/ASP.NET-2.0-Tips_2C00_-Tricks_2C00_-Recipes-and-Gotchas.aspx...
# ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, August 03, 2006 2:16 AM by My Blog
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, August 03, 2006 12:04 PM by knave
Your blog is so good and filled with interesting things that its a daily task for me to take a peek at for new posts! Keep it up!
# ScottGu's tips and tricks
Thursday, August 03, 2006 8:16 PM by CallContext

I'm only really making this entry so I can keep the link in the BAS (Blog Attached Storage), but both of you might be interested in having this around.
# Consejos, trucos, recetas y trampas de ASP.NET 2.0
Friday, August 04, 2006 11:33 AM by .NET a 2.860 m de altura

Scott Guthrie es uno de los padres de ASP.NET, dentro de Microsoft es conocida la historia de...
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Friday, August 04, 2006 11:59 AM by Willie L.
Scott, Terrific...It's an awesome list and very helpful references. You're great! Thanks a lot.
# My ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas "Highlights Page"
Monday, August 07, 2006 4:16 AM by ナオキにASP.NET(仮)

ScottGu's Blogからです。 My ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas "Highlights Page"...
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Monday, August 07, 2006 10:01 AM by Daniel
Hi, just wondering if there are any articles on MSDN on how to tackle 2 way data binding on complex objects aka composite objects? Seems to be a bit of a black hole in terms of documentation or at least my ability to find it. Cheers dan.
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, August 08, 2006 12:51 AM by ScottGu

Hi Daniel,

For tutorials on 2 way databinding, I'd recommend checking out this tutorial series: http://weblogs.asp.net/scottgu/archive/2006/06/22/454436.aspx as well as the quickstart samples on data: http://www.asp.net/quickstart

Hope this helps,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, August 08, 2006 6:45 AM by Daniel
Hi Scott, Thanks for the quick reply. I have seen these articles and they all use typed data sets. I have a collection of complex objects that I am binding to. if I have Simple properties such as Person.Name then it works fine, no problems, however if I have a property that is an object and I try to access its properties, i.e Person.Address.Postcode then databinding fails. I have worked around this by handling the objectdataSource Updating event and adding the values into the object manually however I was wondering / hoping that there is a better solution for this? cheers dan.
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Friday, August 11, 2006 2:52 AM by ScottGu

Hi Dan,

You can do 1 way evaluation of complex objects using the <%# Eval() %> syntax:

<%# Eval("Person.Address.Postcode") %>

Unfortunately two-way binding of sub-properties via the <%# Bind %> syntax isn't supported though. For these types of operations you'd want/need to use the event approach you mentioned above.

Hope this helps,

Scott
# Tip/Trick: Show Detailed Error Messages to Developers
Saturday, August 12, 2006 2:09 PM by ScottGu's Blog

Problem: You are developing/maintaining an ASP.NET web-site, and would like the ability to conditionally
# Collection Scott Gu's of ASP .Net posts
Monday, August 14, 2006 6:15 PM by .hibri
# ASP.NET 2.0 Tipps, Tricks, Rezepte und Gotchas
Tuesday, August 15, 2006 5:52 PM by

Scott Guthrie's Blog ist einfach immer wieder eine Freude! Heute fand ich seine populärsten Artikel...
# Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option
Wednesday, August 16, 2006 3:54 AM by ScottGu's Blog

One scenario that many large development teams often ask me about is whether it is possible to split
# Una risorsa fondamentale per il mio lavoro
Tuesday, August 29, 2006 11:50 AM by Maurizio Tammacco

Di questo linkne faccio un post nel mio blog per tenerlo sempre a portata di....mouse!. Trattasi...
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, August 30, 2006 12:06 PM by chris
Hi scott, one problem i always face is the treeview state in a masterpage. It never keeps its state and the nodes get collapsed. Is there any article on how to keep the state?
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, August 31, 2006 1:49 AM by ScottGu

Hi Chris,

One approach you could take would be to add a Page_Load event handler within the master-page, and use it in conjunction with the SiteMap API to expand the current node in the site that you are visiting.

Hope this helps,

Scott
# Data Source Control vs. Simple Data Coding
Saturday, September 16, 2006 6:19 PM by JaiPrakash
Hi Scott, I want to know whether the use of data source control provided with ASP.NET 2.0 are better than the hand coding or not.I am little confuse about this..... What should i use Data Source Control or Hand Coding.(Pros & Cons of both). As with coding transaction management is easy but is it easy or necessary with Data Source Controls like (SQLDataSource Control or AccessDataSource Controls) If u can please tell me with some experimental approach...........
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Sunday, September 17, 2006 2:18 AM by JaiPrakash
Hi Scott, Please tell me that if is there any issue(Web Hosting) in using ATLAS extender or controls instead of ASP.NET 2.0 normal controls. Please tell me that ATLAS is supported by normal ASP.NET 2.0 hostings???????
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, September 19, 2006 12:12 AM by ScottGu

Hi Jai,

Atlas Control Extenders are fully supported with hosting scenarios.

Hope this helps,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, September 19, 2006 12:13 AM by ScottGu

Hi Jai,

DataSourceControls basically encapsulate the code you'd otherwise write by hand. So if you still want to write it by hand you can definitely continue to-do so.

Hope this helps,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, September 19, 2006 5:52 AM by JaiPrakash
Hi Scott, Thanks Sir,,,,Your suggestions are always good...........always simple, straight and effective.... Thanks
# Mulitple Website and Single Sign in
Saturday, September 23, 2006 10:24 AM by JaiPrakash
Hi Scott, I have a problem related to Login System. I am developing 3 websites for some institution.Now they want that if anybody had sign up for there site1.com(say), than he or she should be able to sign in for site2.com and site3.com. hence, if user has sign up for the membership of site1.com than he/she should automicallly become the member of site2.com and site3.com. and also if the member sign in for the site1.com and if opens sign2.com or site3.com than there he/she must be shown as "Already Login" Anybody Please tell me how can i make a Login System(with 1000% security) which is available to mulitple websites. If possible give some reference also...... Thanks in advance.........
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Sunday, September 24, 2006 11:57 AM by ScottGu

Hi Jai,

I believe what you are looking for is a single-sign-on (SSO) solution. That way the user doesn't have to sign-in to other sites.

I've haven't used these two links myself, but below are two articles that might help:

http://www.microsoft.com/technet/security/topics/identitymanagement/idmanage/default.mspx?mfr=true

http://www.wwwcoder.com/main/parentid/258/site/4922/68/default.aspx

Hope this helps,

Scott
# Tip/Trick: Guard Against SQL Injection Attacks
Saturday, September 30, 2006 12:16 PM by ScottGu's Blog

SQL Injection attacks are reallynasty security vulnerabilities, and something all web developers (regardless
# Una risorsa fondamentale per il mio lavoro
Tuesday, October 03, 2006 10:05 AM by Maurizio Tammacco's blog

Di questo linkne faccio un post nel mio blog per tenerlo sempre a portata di....mouse!. Trattasi...
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, October 25, 2006 8:41 AM by Prabakar Samiyappan
Its Nice and very Intresting to read all the Articles.its a good link which is to added in favorites...
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, November 09, 2006 10:42 AM by Irfan
Hi Scott, I've quick question regarding the asp:treeview in VS2005. I'm a novice to VS2005, i am trying create a custom treeview by inheriting the WebControls.Treeview, everything work fine except when a parent node is clicked it doesn't expand the child node. It gives me the following error. 'childNodes.0' is null or not an object I checked the viewsource and found out that each node is given an ID, if it as a parent-child relation. Please help me. Thanks, Irfan
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, November 22, 2006 4:05 AM by philemon wachara

I need help with xp_cmdshell, using VWD2005 and SQL2005 Express Edition. Despite enabling this feature using the surface area configuration, I still cannot run a stored procedure using xp_cmdshell. Any idea what I could be doing wrong? Thanks in advance.
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, November 29, 2006 2:18 AM by Ekambaram

Hi Scott, If both C# and VB.net Code is there,fine and Its a good link which is to added in favorites...
# Resizing a web page
Thursday, December 07, 2006 1:05 PM by Ray Levron

Scott,

I am trying to use Javascript to resize a gridview control vertically as a user resizes a web page vertically with his mouse. Can you point me in the right direction for that?

regards,

Ray Levron
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, December 07, 2006 11:40 PM by ScottGu

Hi Ray,

Unfortunately I don't know off the top of my head of a sample that does this.

Sorry!

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, December 28, 2006 2:53 PM by raymondo

Hi scott ure posts have been a great help. just need to ask ya, how to batch update through a datlist control, without using business layers as shown on the tutorials on te asp.net website and instaed of the the northwind mdf database iam using sql server 2005. Any help or directions towards tutorials would be great. just to let u know iam a beginner at asp.net 2.0

thanks

raymondo
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Monday, January 08, 2007 3:59 PM by Erick

Hi Scott, I wan to make my own Treeview control has the same behavior like one appears when i install VS .net 2005, i mean when i check a treenode with children... they all appears checked too, and if the parent is unchecked... and then i checked one of its childs... parent treenode get checked but with gray color. I know that when i check or uncheck a treenode althougth i had set OnCheckChange method... it will not do anything till i do a postback action like a simple button. So... how could i do this? thanks...
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Friday, January 19, 2007 12:39 AM by ARC

Hi Scott. Your blog is a great asp.net resource and as i am new to asp.net, it has helped me in many ways. I have one question to ask, I have a master page that uses

some images and a css file that are placed in root\images folder. if i use deny users="?" in root web.config and go to login.aspx, the master page is loaded but without images or css styles. I have to place a web.config in the images folder with allow users="*" to make master page work correctly. Is my solution correct or is there something i have missed? or is there a better/recommended way to do it?

Shouldn't asp.net allow master pages to load resources from subfolders even with anonymous user?
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Friday, January 19, 2007 9:04 PM by ScottGu

Hi ARC,

I believe this blog post will fix your problem: http://weblogs.asp.net/scottgu/archive/2006/01/31/437027.aspx

Hope this helps,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, January 23, 2007 5:28 PM by Nathanael Jones

I just went back and read the comments on

http://weblogs.asp.net/scottgu/archive/2006/04/11/Don_1920_t-run-production-ASP.NET-Applications-with-debug_3D001D20_true_1D20_-enabled.aspx

I'll look into publishing the .pdb files.

Thanks.
# Posting Issues
Wednesday, January 24, 2007 11:10 AM by Nathanael Jones

What is the maximum allowed post length? I've tried to post 3 times now. I receive no error message, but it doesn't appear even after 16 hours.
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, January 24, 2007 11:53 AM by ScottGu

Hi Nathaneal,

The maximum post length by default is about 2MB. You can configure it to a larger size within the maxRequestLength property on the section within your web.config file.

Hope this helps,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, January 24, 2007 1:34 PM by Nathanael Jones

Sorry, I was referring to the max size for comments on this blog.
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, January 24, 2007 1:53 PM by Nathanael Jones

I've placed my question on a separate page instead.

http://nathanael.jones.googlepages.com/question

Thanks,

Nathanael
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, January 25, 2007 8:25 AM by Nathanael Jones

I've succeeded in rewriting 404 requests from IIS back to their original url in ASP.NET, but IIS 5.1 doesn't allow post-backs to unmapped extensions.

Does IIS6 allow the POST verb to unmapped extensions?

How bad is the performance hit when IIS is configured to send * to the runtime?

Thanks,

Nathanael
# URL Rewriting
Thursday, January 25, 2007 9:21 AM by Nathanael Jones

I just read that ASP.NET 2.0 is now capable of sending requests back to IIS for proccessing, so mapping * to aspnet_isapi.dll doesn't invoke a performance hit.

I originally read something (probably regarding 1.1), that stated how deadly it was to map * to aspnet_isapi.dll, due to performance issues.

Is this correct? I've tried to do URL mapping in various ways without this, and failed miserably. I have tried leveraging the 404 rewrite in IIS, using a mixed rewrite/redirection system, and many other less successful approaches.

Thansk,

Nathanael
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, January 30, 2007 12:36 AM by ScottGu

Hi Nathanael,

You can now enable * mapping much more efficiently using IIS6. For static files (like .htm and .asp), ASP.NET will then call back into IIS to have it process them.

Can you send me an email regarding url rewriting? I can then loop you in with someone to help.

Thanks,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, January 30, 2007 10:53 AM by Nathanael Jones

Thanks! That lets me sleep easier.

I found a solution to my most pressing issues. You can view it here (I will try to post it below, but I don't know if it will take. My last one didn't).

http://nathanael.jones.googlepages.com/resolution

The last three questions are still relevant, if less important. Due to the lack of documentation, and 'black-box' nature of ASP.NET, I'm not too confident about these.

Thanks,

Nathanael

What do you use for URL and path manipulation? I know the runtime uses System.Web.VirtualPath and System.Web.Util.UrlPath, but they are marked ‘internal’. I’ve had to create my own class to maintain URL-parsing consistency.

Is there a reason why ASP.NET uses redirection instead of URL rewriting for error pages? I personally find it much easier to deal with errors and 404s if the URL doesn’t change on me. I hate it when I misspell one character, and the server redirects me to a new URL, denying me the chance to rectify my mistake. I have implemented a custom system in global.asax that uses Server.Transfer to handle error messages; the admin is given a page with descriptive exception details, while all the other unauthenticated users are provided with a generic message. Is this an acceptable approach?

Is it fine to ignore the url authorization system and simply use User.IsInRole throughout my code? Many of my pages do not have very clear-cut security requirements, and must perform complex role checks.
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, January 30, 2007 1:49 PM by Nathanael Jones

Ok, I have another problem...

I am caching ASP.NET snippets in the database for the summary field on each article.

As the paths in each snippet are relative to the parent article file, I have been creating an instance of Page and using the ParseControl method. Unfortunately, this seems to simply bring back a LiteralControl instead of the proper hierarchy.

What do you reccomend?
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, January 31, 2007 8:36 AM by Nathanael Jones

Addendum: I mean AppRelativeTemplateSourceDirectory, not TemplateSourceDirectory. Also, this property must be set recursively. See example below.

========================

///

/// Recursively sets the AppRelativeTemplateSourceDirectory property on the specified control and all of its children

///


///

///

public static void SetPathRecursive(Control c, string AppRelativeTemplateSourceDirectory) {

if (c == null) return;

c.AppRelativeTemplateSourceDirectory = AppRelativeTemplateSourceDirectory;

foreach (Control child in c.Controls) {

SetPathRecursive(child, AppRelativeTemplateSourceDirectory);

}

}

///

/// Renders the specified code to the specified output stream

///


/// The code to render

///

/// The parent page

/// The path the specified code should be virtually executed from. The location relative paths are resolved from

public static void RenderCode(string code, TextWriter output, Page parent, string AppRelativeTemplateSourceDirectory) {

//Parse the text into a control object (a container control object is created automatically.

Control c = parent.ParseControl(code);

SetPathRecursive(c, AppRelativeTemplateSourceDirectory);

//Render to the control

XhtmlTextWriter htw = new XhtmlTextWriter(output);

c.RenderControl(htw);

}
# Update
Tuesday, February 06, 2007 1:33 PM by Nathanael Jones

The ContentPlaceHolder patch described on http://nathanael.jones.googlepages.com/resolution isn't working properly... All of the paths are rendered by HtmlLink as if the control is located in the application root. If I set the AppRelativeTemplateSourceDirectory to "~/content/downloads/articlefolder", I get worse issues. The path resolves twice, as in "content/downloads/articlefolder/content/downloads/articlefolder/stylesheet.css" Wacky. This is when good documentation is really missed....

What do I try next? Control adapters?

Please help.

Thanks,

Nathanael Jones
# The Infamous HtmlLink
Tuesday, February 06, 2007 3:02 PM by Nathanael Jones

Apparently there wasn't any problem with the code I posted... A little quirk with the HtmlLink control was tripping me up.

In a few master pages I used the Control.RenderControl method on all children of the ContentPlaceHolder object inside the HEAD.

This was used to pull out information from the meta tags and display the posted date. This had the side effect of triggering a RenderControl on my HtmlLink controls before render-time.

See ContentPlaceHolder patch, http://nathanael.jones.googlepages.com/resolution)

HtmlLink renders correctly the first time the function is called, but starts duplicating and corrupting the href element on subsequent calls. Yet another GOTCHA for the list.

Truly, this project has been agonizing like no other. Reverse engineering device drivers is lots of fun in comparison.
# offline client
Monday, February 26, 2007 4:50 AM by Yenkay

hi Scott,

I am developing an e-magazine in asp.net 2.0 and SQL server. I want to develop an Offline Client to view the magazine offline. Any ideas about creating an Offline Client application for ASP.Net application with DB Operation.

Thanks in Advance

yenkay
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Tuesday, February 27, 2007 2:24 AM by ScottGu

Hi Yenkay,

Developing an offline application using ASP.NET is pretty hard (since it needs to be connected to a web-server).

I'd probably recommend building a Windows Forms or WPF client application instead. This will enable you to work disconnected from a web-server.

Hope this helps,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Saturday, March 03, 2007 12:27 PM by Tom

Scott,

Do you have any links to information on the process of developing an ASP.NET web application using Team Foundation Server? If not, I'd love to see some posts from you along those lines or some howto videos/articles on the subject.

Interested in having my small team of developers (3) able to checkout files, update them, test/debug their changes to the site locally on the machine and then when they check in the files, only then would the changes be reflected on the development IIS server.

Thanks in advance for any help/links you can provide.

-Tom
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Saturday, March 03, 2007 9:15 PM by ScottGu

Hi Tom,

I don't know of some off the top of my head, but Brian Harry has a great blog here and might be able to help: http://blogs.msdn.com/bharry

He runs the TFS team and blogs a lot about it.

Thanks,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Wednesday, March 07, 2007 6:19 PM by Shawn Palmer

On Aug 8 there was a post that stated, "I have worked around this by handling the objectdataSource Updating event and adding the values into the object manually..." Can you show an example of how to get at the object that is created?

For example, I have the below and before that update method is called I need to set a property on that Employee object that is passed to Update.

.aspx

dataobjecttypename="mynamespace.Employee"

updatemethod="Update"

.aspx.cs

protected void objectsource_Updating(object sender, ObjectDataSourceMethodEventArgs e)

{

...

}

Employee.cs

[DataObjectMethod(DataObjectMethodType.Update, true)]

public static bool Update(Employee o)

{

o.Save();

return true;

}
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, March 08, 2007 4:57 PM by ScottGu

Hi Shawn,

I believe you can add the values using the "e" parameter to the updating event above. I believe there is a Params collection there where you can add any custom values you want.

Hope this helps,

Scott
# re: ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas
Thursday, March 15, 2007 9:32 AM by Very useful post

do you have tips for VS 2005 and database express?
# ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas « ???
Tuesday, May 22, 2007 11:24 AM by ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas « ???

Pingback from ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas « ???
# Enlaces 31 de Mayo: ASP.NET, ASP.NET AJAX, Visual Studio y.NET « Thinking in .NET
Friday, June 01, 2007 12:13 PM by Enlaces 31 de Mayo: ASP.NET, ASP.NET AJAX, Visual Studio y.NET « Thinking in .NET

Pingback from Enlaces 31 de Mayo: ASP.NET, ASP.NET AJAX, Visual Studio y.NET « Thinking in .NET
# .NET Tips & Tricks
Wednesday, June 13, 2007 3:18 PM by Michael's Coding Den

Last update: June 13 , 2007 Document version 0.6 Preface If you have something to add, or want to take
# Tip/Trick: Creating Packaged ASP.NET Setup Programs with VS 2005
Friday, June 15, 2007 3:48 PM by ScottGu's Blog

Scenario You have built an ASP.NET Web Application using Visual Studio 2005, and want to enable customers
# Tip/Trick: Creating Packaged ASP.NET Setup Programs with VS 2005
Friday, June 15, 2007 5:30 PM by BusinessRx Reading List

Scenario You have built an ASP.NET Web Application using Visual Studio 2005, and want to enable customers
# Tip/Trick: Creating Packaged ASP.NET Setup Programs with VS 2005
Friday, June 15, 2007 6:01 PM by ASP.NET

Scenario You have built an ASP.NET Web Application using Visual Studio 2005, and want to enable customers
# tips on how to blog » How To Blog -
Sunday, June 17, 2007 5:05 AM by tips on how to blog » How To Blog -

Pingback from tips on how to blog » How To Blog -
#   Building and using a LINQ for SQL Class Library with ASP.NET 2.0 by diet.MEDtrials.info
Friday, July 27, 2007 3:27 PM by Building and using a LINQ for SQL Class Library with ASP.NET 2.0 by diet.MEDtrials.info

Pingback from   Building and using a LINQ for SQL Class Library with ASP.NET 2.0 by diet.MEDtrials.info
# Getting Started with ASP.NET 2.0 | GrantPalin.com
Friday, August 24, 2007 10:31 PM by Getting Started with ASP.NET 2.0 | GrantPalin.com

Pingback from Getting Started with ASP.NET 2.0 | GrantPalin.com
# Tip/Trick: Automating Dev, QA, Staging, and Production Web.Config Settings with VS 2005
Friday, September 21, 2007 4:31 AM by ScottGu's Blog

One of the questions I get asked fairly regularly is: "how can I can easily change different configuration
# Tip/Trick: Automating Dev, QA, Staging, and Production Web.Config Settings with VS 2005
Friday, September 21, 2007 5:29 AM by Elan's Aggregated Blogs

One of the questions I get asked fairly regularly is: "how can I can easily change different configuration
# Tip/Trick: Automating Dev, QA, Staging, and Production Web.Config Settings with VS 2005
Friday, September 21, 2007 5:42 AM by ASP.NET

One of the questions I get asked fairly regularly is: "how can I can easily change different configuration
# Dicas de ASP.NET 2.0
Friday, September 21, 2007 8:00 PM by Desenvolvimento

Mais uma vez, navegando pelo blog do Scott Guthrie , encontrei um post dele que traz uma lista de dicas
# Scott Guthrie Stories
Tuesday, September 25, 2007 7:39 PM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com
# Tip/Trick: Building a ToJSON() Extension Method using .NET 3.5
Tuesday, October 02, 2007 6:22 PM by Blogs

Earlier this year I blogged about a new language extensibility feature of C# and VB called "Extension
# 技巧/诀窍:用 .NET 3.5 创建 ToJSON() 扩展方法 (木野狐译)
Tuesday, October 09, 2007 10:53 PM by Joycode@Ab110.com

【原文地址】 Tip/Trick: Building a ToJSON() Extension Method using .NET 3.5 【原文发表日期】 Monday, October 01, 2007
# ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas « Private: .NET + OO concept + RIA(AJAX)
Wednesday, December 05, 2007 4:52 AM by ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas « Private: .NET + OO concept + RIA(AJAX)

Pingback from ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas « Private: .NET + OO concept + RIA(AJAX)
# MSDN Blog Postings » Scott Guthrie's ASP.NET tips, tricks and gotchas
Tuesday, December 18, 2007 5:26 AM by MSDN Blog Postings » Scott Guthrie's ASP.NET tips, tricks and gotchas

Pingback from MSDN Blog Postings » Scott Guthrie's ASP.NET tips, tricks and gotchas
# Scott Guthrie's ASP.NET tips, tricks and gotchas
Tuesday, December 18, 2007 5:34 AM by Noticias externas

And for those of you who are using ASP.NET - Scott Guthrie also has a great series articles on ASP.NET
# 技巧/诀窍:在ASP.NET中重写URL(转)
Thursday, January 17, 2008 9:33 PM by 绿毛虫

技巧/诀窍:在ASP.NET中重写URL 【原文地址】Tip/Trick:UrlRewritingwithASP.NET

【原文发表日期】Monday,February26,...
# Jan 24th Links: ASP.NET, ASP.NET AJAX, Visual Studio, .NET, IIS
Friday, January 25, 2008 3:07 AM by ASPInsiders

I just arrived back from my trip from Asia, and decided to celebrate (since I'm jet-lagged and can't
# Links 6/Fev: ASP.NET, ASP.NET AJAX, Visual Studio, .NET, WPF
Saturday, March 15, 2008 9:31 PM by Mutamblog

Links 6/Fev: ASP.NET, ASP.NET AJAX, Visual Studio, .NET, WPF
# xhtmlConformance mode="Legacy" vs ASP.NET AJAX
Wednesday, April 02, 2008 10:20 AM by www.podlipensky.com

xhtmlConformance mode="Legacy" vs ASP.NET AJAX
# 28ste April links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Silverlight
Wednesday, April 30, 2008 11:14 AM by Scott Guthrie's Blog in Dutch

Hier vind je mijn laatste link-lijst series . Bekijk ook mijn ASP.NET Tips, Tricks and Tutorials pagina
# My Top 100 Favourites
Wednesday, May 21, 2008 10:32 AM by Doug Bornyk

1 ASP.NET ASP.NET Official Site 2   DotNetVideos 3 Development MSDN 4   Code Plex 5  
# Links op 20 mei: ASP.NET, ASP.NET AJAX, .NET, Visual Studio, Silverlight, WPF
Saturday, May 24, 2008 3:38 AM by Scott Guthrie's Blog in Dutch

Mijn verontschuldigingen voor de weinige posts de laatste weken. Mijn werk en leven zijn enorm de druk
# Collegamenti del 6 Febbraio, ASP.NET, ASP.NET AJAX, Visual Studio, .NET, WPF
Tuesday, June 10, 2008 7:35 PM by ScottGu Italian

Collegamenti del 6 Febbraio, ASP.NET, ASP.NET AJAX, Visual Studio, .NET, WPF
# Ultracet.
Thursday, August 07, 2008 3:44 AM by Ultracet.

Is ultracet addictive. Ultracet.
# Tips and Tricks News
Wednesday, August 27, 2008 4:17 PM by John Stagich's Blog

Tips and Tricks News
# Enlaces del 10 de Octubre: ASP.NET, ASP.NET AJAX, jQuery, IIS « Thinking in .NET
Sunday, October 12, 2008 4:58 AM by Enlaces del 10 de Octubre: ASP.NET, ASP.NET AJAX, jQuery, IIS « Thinking in .NET

Pingback from Enlaces del 10 de Octubre: ASP.NET, ASP.NET AJAX, jQuery, IIS « Thinking in .NET
# Concept Cars - 14. Toyota Fine-X
Thursday, October 23, 2008 11:03 PM by Concept Cars - 14. Toyota Fine-X

Pingback from Concept Cars - 14. Toyota Fine-X
# Enlaces a 22 de Octubre: ASP.NET, Visual Studio, WPF y Silverlight « Thinking in .NET
Saturday, October 25, 2008 7:28 PM by Enlaces a 22 de Octubre: ASP.NET, Visual Studio, WPF y Silverlight « Thinking in .NET

Pingback from Enlaces a 22 de Octubre: ASP.NET, Visual Studio, WPF y Silverlight « Thinking in .NET
# Nov 6th Links: ASP.NET, ASP.NET AJAX, jQuery, ASP.NET MVC, Silverlight and WPF
Thursday, November 06, 2008 4:20 AM by Community Blogs

Last week was our big PDC conference, and I've been busy catching up back at work this week. 

Controlling HTML Checkboxes within Your Web Page

Sometimes it's desirable to control whether or not certain checkboxes are checked, or to do something depending on which ones are checked.

Although CGI scripts can do their own error checking and display messages to the form user as needed, letting JavaScript do some of the preliminary checks can be faster and less frustrating for the form user.

This article shows you how to use JavaScript to determine if certain checkboxes are checked and how to check and uncheck checkboxes. Four useful working examples are provided to assist understanding:

1. Limiting the number of checkboxes that can be checked, useful when the user is allowed to check only a certain number of checkboxes. For example, you might have a list of six reports and the customer may select up to three to get free with an order.

2. Totaling the value of checked checkboxes, useful when customers check items they want to order and you want to present the current order total whenever a check or uncheck is performed.

3. Checking or unchecking a group of checkboxes by clicking a button, useful when you have a large number of checkboxes where users might want to check or uncheck all of them. A simple button click can be user-friendly.

4. A checkbox can be checked to represent checking all checkboxes of a group, and a checkbox can be checked to represent unchecking all of them. This is useful for the same reason as number 3. Either method can be used.

First, I'll show you how to determine whether or not a checkbox has been checked and how to check and uncheck them using JavaScript.

The form must have a name. And the checkbox fields must have a name. Here is an example:

name="myform"
method="POST"
action="/cgi-bin/script.cgi">
type="checkbox"
name="box1"
value="yes1">
type="checkbox"
name="box2"
value="yes2">
type="submit"
onClick="DoTheCheck()">


The above form's name is "myform". The checkbox's names are "box1" and "box2".

Here is JavaScript that will check whether or not the checkboxes are checked and display an alert box with the answer. It is function DoTheCheck() that the above form calls when the submit button is clicked. The JavaScript can be in the HEAD area or in the BODY area, so long as it is above the form it manipulates.

function DoTheCheck() {
if(document.myform.box1.checked == true)
{ alert('box1 is checked'); }
if(document.myform.box1.checked == false)
{ alert('box1 is not checked'); }
if(document.myform.box2.checked == true)
{ alert('box2 is checked'); }
if(document.myform.box2.checked == false)
{ alert('box2 is not checked'); }
}

The format is the word "document," a period, the name of the form, a period, the name of the checkbox field, a period, and the word "checked."

If you want to check a checkbox with JavaScript, use:

document.myform.box1.checked = true;

Notice that when you consult the checkbox to see whether or not it is checked, you use two consecutive equals characters; and when you assign a check to the checkbox, you use only a single equals character. The single use means "make it equal to ______." The doubled use determines "whether or not it already is equal to ______."

If you want to un-check a checkbox with JavaScript, use:

document.myform.box1.checked = false;

Now you know how to determine whether or not a checkbox is already checked and you can check or uncheck it.

Before we present the examples, let's learn how to determine the value of a checkbox.

Simply replace the word "checkbox" with the word "value". The value is the value as specified in the form itself (unless JavaScript is used to change that value). When you consult the checkbox to determine its value, it will provide the value whether or not it is checked. For example, this will display an alert box with the value of box1 as the message:

alert(document.myform.box1.value);

To display the alert box only if the checkbox is checked, do this:

if(document.myform.box1.checked == true)
{ alert(document.myform.box1.value); }

If you need to change the value of a checkbox with JavaScript, do something like this:

document.myform.box1.value = "new value";

Now, let's talk about the four examples.

Please download the demonstration JavaScript before proceeding. The demo page has a link to a bare demonstration page, which you can save to your hard drive, and it has a link to a ZIP file with the same bare demonstration page.

The following are short descriptions of each demonstration form and it's JavaScript. The demonstrations can be modified as you see fit.

1. Limiting the Number of Checkboxes

The demonstration has checkboxes representing six colors, and the user is asked to select up to three. If the user tries to select more than three, an alert box reminder is displayed.

The JavaScript is function CountChecks(). It scans each checkbox to determine whether or not it's checked. If more than three checkboxes are checked, it

a. Unchecks the last one that was checked by the user, and then

b. Displays the alert box.

2. Totaling the Value of Checked Checkboxes

The demonstration has checkboxes representing four items, with prices ranging from 0.00 to 55.00. There is also a text field. That text field is automatically updated with the total values of all checked checkboxes, every time one is checked or unchecked.

The JavaScript is TotalCheckedValues(). It does the following actions:

a. Scans each checkbox to determine whether or not it is checked,

b. Adds each checked value to a running total,

c. Formats the total into a currency decimal number, and

d. Displays the total in the form's text field.

3. Checking or Unchecking a Group of Checkboxes

The demonstration has checkboxes representing three colors. It also has two buttons, "Check All" and "Un-check All."

The checkboxes can be checked and unchecked individually. The two buttons cause all to be checked and all to be unchecked, respectively.

The JavaScript is two functions, CheckAll() and UnCheckAll().

When the "Check All" button is clicked, function CheckAll() checks all checkboxes. And when the "Un-check All" button is clicked, function UnCheckAll() unchecks all checkboxes.

4. "All" and "None" Checkboxes

The demonstration has checkboxes representing three colors, plus "All" and "None." The "None" checkbox is pre-checked.

The checkboxes representing the three colors can be checked and unchecked individually. If the "All" or the "None" checkbox is checked, all other checkboxes become unchecked.

There will always be at least one checkbox checked.

~ If "All" or "None" are checked, everything else is unchecked.

~ If any one or more of the colors are checked, both "All" and "None" are unchecked.

~ Whenever there is a situation where no checkbox would otherwise be checked, "None" automatically becomes checked.

The JavaScript is four functions, UpdateChecks(), AllIsChecked(), NoneIsChecked(), and BoxesCheck().

The function UpdateChecks() is called every time a checkbox is checked or unchecked. When that function is called, it knows which was checked/unchecked, either the "All," the "None," or one of the color checkboxes.

a. If it was the "All" checkbox, function
AllIsChecked() is called.

i. If the "All" checkbox happens to be unchecked
at the time the function is called, then the
function BoxesCheck() is called to handle
the situation (see c., below).

ii. If the "All" checkbox happens to be checked,
all others are unchecked.

b. If it was the "None" checkbox, function
NoneIsChecked() is called.

i. If the "None" checkbox happens to be
unchecked at the time the function is called,
then the function BoxesCheck() is called to
handle the situation (see c., below).

ii. If the "None" checkbox happens to be checked,
all others are unchecked.

c. If it was one of the color checkboxes, function
BoxesCheck() is called. It

i. Unchecks the "All" checkbox.

ii. Unchecks the "None" checkbox.

iii. If all the colors are checked, then it

A. Checks the "All" checkbox, and

B. Calls the AllIsChecked() function.

iv. If all the colors are unchecked, then it

A. Checks the "None" checkbox, and

B. Calls the NoneIsChecked() function.

---

Now you're on your way to becoming an expert with JavaScript and form checkboxes. It can take a bit of practice, and some trial and error. But once it's understood, you have a skill that can become useful time and again.

Create and Update Database Schema

Introduction

When developing an application using DDD one starts by trying to define a model of the domain for/in which the application should be used. At the same time you try to establish the so called ubiquitous language. At some point you might need to store and or retrieve data into or from a data source. Very often this data source is a relational database. But it's not necessarily always the case. It could as well be a web service or a XML document. That leads me to the notion that "the database is just an implementation detail of the application". Or if I turn this sentence a little bit around "...it should not be the database (-schema) that determines the design of an application but rather should the database schema be a natural outcome of the domain model...". I know, this is NOT what a DBA likes to hear. But trust me I have developed many applications in the past where the first thing that was designed of the application was the entity relationship diagram (ERD)... I have also implemented quite a lot of stored procedures on Oracle and SQL server in the past. So I know both sides of the argument.

Assuming that the database schema should be an implementation detail of the overall application it would be great if the schema could be somehow auto-generated from the domain model. As you might expect, when using NHibernate as the ORM tool this is possible. We have to distinguish between the two possibilities

* (re-) create a new schema from scratch
* updating an existing schema

Create Schema
The model

To start we define a very basic model

image
The Mappings

In our data layer we define the two mapping files Product.hbm.xml and Category.hbm.xml. The former's content is




namespace="Domain"

assembly="Domain">

















and the latter's content is




namespace="Domain"

assembly="Domain">















Note that we have defined only the absolute minimum needed and rely heavily on the (meaningful) defaults provided by NHibernate.
Tests

To analyze the database schema creation script generated by NHibernate we write the following test

[TestFixture]

public class CreateSchema_Fixture

{

private Configuration _cfg;



[SetUp]

public void SetupContext()

{

_cfg = new Configuration();

_cfg.Configure();

_cfg.AddAssembly(Assembly.LoadFrom("DataLayer.dll"));

}



[Test]

public void Create_a_database_schema_creation_script()

{

var export = new SchemaExport(_cfg);

var sb = new StringBuilder();

TextWriter output = new StringWriter(sb);

export.Execute(true, false, false, false, null, output);

}

}

Note that the configuration file hibernate.cfg.xml has the following content in our case







NHibernate.Connection.DriverConnectionProvider

NHibernate.Dialect.MsSql2005Dialect

NHibernate.Driver.SqlClientDriver

Server=(local);Database=NHibernateFAQ;Integrated Security=SSPI;



true





That is, we are using a SQL Server 2005 database called NHibernateFAQ. It is not necessary to have SQL Server 2005 installed though since we are only generating (and analyzing) the scripts generated by NHibernate and not accessing the database itself!

The output generated by the above test is similar to this

if exists (select 1 from sys.objects

where object_id = OBJECT_ID(N'[FK1F94D86A9F364CC5]')

AND parent_object_id = OBJECT_ID('Product'))

alter table Product drop constraint FK1F94D86A9F364CC5



if exists (select * from dbo.sysobjects

where id = object_id(N'Product')

and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table Product

if exists (select * from dbo.sysobjects

where id = object_id(N'Category')

and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table Category



create table Product (Id UNIQUEIDENTIFIER not null,

Name NVARCHAR(255) null,

Category UNIQUEIDENTIFIER null,

primary key (Id))

create table Category (Id UNIQUEIDENTIFIER not null,

Name NVARCHAR(255) null,

primary key (Id))



alter table Product add constraint FK1F94D86A9F364CC5

foreign key (Category) references Category

That's really wonderful for a quick shot!

The default for a column is that it is nullable and the default type and length for a string type field is NVARCHAR(255).
Mandatory columns and maximal length of column

But there are a few details that we might want to improve. First we want to make the Name columns mandatory (NOT NULL). Nothing easier than that; just add an attribute not-null="true" to the mapping files where appropriate. Also we want to limit the length of the Name column to given amount, e.g. 50 characters. Just add a length="50" to the appropriate property of the mapping files. The create table part of the schema creation script is then

create table Product (Id UNIQUEIDENTIFIER not null,

Name NVARCHAR(50) not null,

Category UNIQUEIDENTIFIER null,

primary key (Id))



create table Category (Id UNIQUEIDENTIFIER not null,

Name NVARCHAR(20) not null,

primary key (Id))

Foreign Keys

There is still a detail in the script that might disturb you. It's the name of the foreign key constraint between the Product and the Category tables. If we want to choose a name we can use the foreign-key attribute on the many-to-one node of the mapping file, e.g.



now the corresponding snippet of the script is

if exists (select 1 from sys.objects

where object_id = OBJECT_ID(N'[fk_Product_Category]')

AND parent_object_id = OBJECT_ID('Product'))

alter table Product drop constraint fk_Product_Category

...

alter table Product add constraint fk_Product_Category

foreign key (Category) references Category

Unique Constraints

If we want to guarantee that the Name property of the Category class is unique we can do this by either using business logic to enforce this requirement or define a unique constraint on the database. Let's have a look at the latter. Just add the attribute unique="true" to the mapping of the Name property in the mapping file for the Category class. That is



and the script generated is this

create table Category (

Id UNIQUEIDENTIFIER not null,

Name NVARCHAR(20) not null unique,

primary key (Id)

)

If you want to define a unique constraint which spans multiple columns then you have to resort to the attribute unique-key. Let's assume we have a Person class like

public class Person

{

public Guid Id { get; set; }

public string FirstName { get; set; }

public string LastName { get; set; }

}

and we want to define a unique constraint on the combination of the FirstName and LastName columns then our mapping file looks like this




namespace="Domain"

assembly="Domain">

















Note that the name you choose for the unique-key is not important (here "uk_Person_Name"). Just use the same name for all columns that make up for a unique constraint. The create table script generated by NHibernate is then

create table Person (

Id UNIQUEIDENTIFIER not null,

FirstName NVARCHAR(50) not null,

LastName NVARCHAR(50) not null,

primary key (Id),

unique (FirstName, LastName)

)

Indices

We might also want to tune our database schema and define some indices. Often we might search for a product by its name and thus the Name column might be a good candidate for an index. How can we do this. Well it's again very easy. Just add the attribute index to the right property tag in the product mapping file and provide a name for the index. That is



now our create script will look like this (note the second last statement where the index is created)

create table Category (Id UNIQUEIDENTIFIER not null, ...)

create table Product (Id UNIQUEIDENTIFIER not null, ...)

create index idx_Product_Name on Product (Name)

alter table Product add constraint fk_Product_Category ...

Check Constraints

We can also define some check constraints on our columns in the database. Let's assume our product has a UnitsOnStock property which must be greater or equal than zero. To define this constraint on the database column we can define the mapping of UnitsOnStock as follows







Note that there is no check attribute defined for the property tag. Thus we have to use the child tag column for this purpose. The create table script is then

create table Product (

Id UNIQUEIDENTIFIER not null,

Name NVARCHAR(50) not null,

UnitsOnStock INT null check( UnitsOnStock >= 0) ,

Category UNIQUEIDENTIFIER not null,

primary key (Id)

)

Update Schema

Once we have an existing database schema which we cannot re-create from scratch (because we might already have a first version of our application in production with productive data...) we need another technique. Fortunately NHibernate provides us the possibility to update an existing schema, that is NHibernate creates an update script which can the be applied to the database.

As usual we want to define a unit test for this situation. In the setup for the unit test I'll predefine a first version of my database schema. This time we need to have a database installed on the system (in our case SQL Server 2005) since this first version of the schema is generated in the database otherwise update schema will not work.

So let's have a look at the setup

[TestFixture]

public class UpdateSchema_Fixture

{

private Configuration _cfg;



public const string product_xml =

""+

"
" namespace='Domain'"+

" assembly='Domain'>"+

" "+

" "+

" "+

"
"+

" " +

"
"+

"
";

public const string category_xml =

""+

"
" namespace='Domain'"+

" assembly='Domain'>"+

" "+

" "+

" "+

"
"+

"
"+

"
";



[SetUp]

public void SetupContext()

{

// Setup "old" database schema

_cfg = new Configuration();

_cfg.Configure();

_cfg.AddXml(product_xml);

_cfg.AddXml(category_xml);

var export = new SchemaExport(_cfg);

export.Execute(false, true, false, false);

}

}

I define 2 strings containing the (first version of the) mapping files for the Category and the Product class. In the SetupContext method I create a configuration object and feed it with these two mapping XML fragments. I then export this schema to the database by creating an instance of the SchemaExport class and calling the Execute method.

Note that the Category mapping fragment does not contain a mapping for the Name column and the Product mapping fragment does not contain a mapping for the relation to the Category class as well as no definition of the UnitsInStock column.

Now I want to test the UpdateSchema class and thus implement the following test

[Test]

public void Update_an_existing_database_schema()

{

_cfg = new Configuration();

_cfg.Configure();

_cfg.AddAssembly(Assembly.LoadFrom("DataLayer.dll"));

var update = new SchemaUpdate(_cfg);

update.Execute(true, false);

}

The update script generated by NHibernate is

alter table Category add Name NVARCHAR(20) unique

alter table Product add UnitsOnStock INT check(UnitsOnStock >= 0)

alter table Product add Category UNIQUEIDENTIFIER

alter table Product add constraint

fk_Product_Category foreign key (Category) references Category

As expected I only get alter statements for existing tables and create statements for the elements missing so far.
Code

You can find the code here. Download it with a SVN client like TortoiseSVN. It's a VS 2008 project.
Summary

When developing a application using DDD the database is often considered an "implementation detail". NHibernate provides us tools to auto-generate create and alter scripts for the database schema from the domain model. I have shown you, by using a simple domain model how to create a schema from scratch and how to alter a pre-existing database schema. I have also discussed various optimization techniques used when creating database schemas as there are unique constraints, indices and check constraints.

Enjoy

Blog Signature Gabriel .

Print | posted on Monday, April 28, 2008 9:52 AM
Comments on this post
# re: Create and Update Database Schema
Requesting Gravatar...
I am having problems getting NHibernate to create the PERSISTED columns:

CREATE TABLE [dbo].[Resource](
[Resource_Id] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](1000) NOT NULL,
[Short_Name] AS ([dbo].[GetNameWithFlat]([Name])) PERSISTED,
[Name_Checksum] AS (checksum([Name])) PERSISTED)

I tried using Formula, but it doesn't create the columns
Left by Dennis on May 21, 2008 10:03 PM
# re: Create and Update Database Schema
Requesting Gravatar...
@Dennis: what is "PERSISTED"? Which Database Product do you use?
Left by Gabriel Schenker on May 22, 2008 12:15 AM
# re: Create and Update Database Schema
Requesting Gravatar...
Hi,
ich have a question to the parameter "unique-key".
What I really want is, that the name would be published too.
Like this:
create table Person (
Id UNIQUEIDENTIFIER not null,
FirstName NVARCHAR(50) not null,
LastName NVARCHAR(50) not null,
primary key (Id),
unique uk_Person_Name (FirstName, LastName)
)

Is this possible?
Thanks

Left by Sandra on Jun 24, 2008 2:44 AM
# re: Create and Update Database Schema
Requesting Gravatar...
@Sandra: as far as I know it is NOT possible!
Left by Gabriel Schenker on Jun 25, 2008 8:45 PM
# re: Create and Update Database Schema
Requesting Gravatar...
@ Gabriel Schenker
What a shame! So migrations of a existing database scheme to a new version becomes more difficult.
Left by Sandra on Jun 25, 2008 9:48 PM
# re: Create and Update Database Schema
Requesting Gravatar...
@Sandra: to migrate an existing schema (in production) to a new version I don't recommend using UpdateSchema but rather a tool like Red Gate's Sql Compare which can produce the necessary alter scripts.
Use UpdateSchema during developement to sync the db's of each developer...
Left by Gabriel Schenker on Jun 26, 2008 7:24 PM
# re: Create and Update Database Schema
Requesting Gravatar...
Hi, Gabriel
Thank you for the great article.
I have a assosiation. But the generate link table has no primary key defined. It just contains two foriegn keys. But there are nothing to make them a combined primary key. Did i miss something?
Left by leilei on Jul 13, 2008 1:34 AM
# re: Create and Update Database Schema
Requesting Gravatar...
@leilei: if you NEED a primary key in the association table you might have a look at "ID-BAG" (please consult the nhibernate doc, or if you have time to wait I'll post an article on this very topic soon)
Left by Gabriel Schenker on Jul 20, 2008 6:07 PM
# Generating constraint names
Requesting Gravatar...
@Gabriel, I too would like to see the constraint names in the generated scripts, as per Sandra's comment.

In my previous job we ran into a lot of trouble when we let SQL Server generate random names for constraints. When the time came to change them, we had problems running our script against mutiple copies of the database as each database had a different name for the constraint!

However I really like this approach as there is no need to keep your scripts under source control any more, just the mapping files.

I wonder if it might be possible for me to submit a patch for NHibernate which will provide this functionality. I have not contributed to OSS before but this could be my first effort.
Left by Ross Neilson on Aug 20, 2008 2:24 AM
# re: Create and Update Database Schema
Requesting Gravatar...
@Ross: every body is highly welcome to provide patches to NHibernate!
You still have some scripts to keep under source control though (when you migrate your productive database from one version to the next you'll probably want to use a tool like Redgate's Sql Compare to generate the alter script...)
Please have a look at:
http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/08/04/manage-sql-databases.aspx
Left by Gabriel Schenker on Aug 20, 2008 4:25 PM
# re: Create and Update Database Schema
Requesting Gravatar...
Gabriel,

We did use Sql Compare, for just that task, it really is a very useful piece of software.

I have got the NHibernate source code downloaded to my PC at home so I will try to produce a patch over the weekend.