Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Disallowing duplicate values
Message
From
05/03/2010 09:23:38
 
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01452754
Message ID:
01452788
Views:
27
>Frank,
>
>The BLG does an OK job of getting you started for business rules. It looks at the database schema and builds (some) rules based on what it sees. As you can see, it does not build a business rule for alternate keys. So you need to build these yourself. This is, however, not difficult. You need to:
>
>1.) Create a stored procedure that returns the record that equals the key value you are attempting to save. Note, you will also need to pass a PK value so that when you are saving an existing record, you don't return the existing record. (When you are adding a new record you pass zero as this parameter and when you are saving an existing record you pass its PK.)
>2.) Add a method in the business object code to call this stored procedure.
>3.) Add code in your method that validates this column to include this check.
>
>Your sp would look something like this:
>
>
>/*  This procedure will return the country passed as parameter if the passed countryID parameter is zero  */
>CREATE PROCEDURE [dbo].[CountrySelectByName]
>(
>	@Name char(40), @CountryID int
>)
>AS
>	SET NOCOUNT ON;
>	SELECT *
>	FROM [dbo].[Country]
>	WHERE 
>		([CountryName] = @Name) and ([CountryID] <> @CountryID)
>		
>
>
>You could also code this to just return a count as opposed to sending back the entity as well, but you get the point.
>
>Now just build your methods and rule code accordingly and your object has a rule to check for dupes.
>
>HTH
>

Hi Bob,

thanks. That looks very helpful. Does Kevin consider enhancement requests? Would something like this be a good one?

I think I've been spoilt by the VMP framework in that it does so much of this for you already so I've been expecting these thing to exist in MM.NET too.

What about when you try to delete a record from a table and there is a foreign key constraint that will fail. Would MM.NET pick that up or do I also have to code that in?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform