New Posts New Posts RSS Feed: Customized StringLengthVerifier
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Customized StringLengthVerifier

 Post Reply Post Reply
Author
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Topic: Customized StringLengthVerifier
    Posted: 22-Feb-2011 at 9:25am

Hi smi-mark,

You are absolutely right. The buddy class will be more usefull if one is trying to override the verifier of one specific entity's property. In the situation where you want to override a verifier "globally", your approach is better suited.
 
I guess I was so excited to share this new feature that ended up neglecting this detail.
 
Thanks for bringing it up.
 
Silvio.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 22-Feb-2011 at 6:58am
If he is trying to replace every string verifier in the edmx, would the template not be the easiest approach? if it was only a few properties then yes the buddy approach would be more practical.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 22-Feb-2011 at 1:09am
Hi Jignesh and smi-mark, 
 
Now you can also use a "buddy" class and create a verifier to override the verifier in the generated code. This way you don't need to customize the designer template.
 
The "buddy" class is a new feature available in DevForce 6.0.8 and you can find more information about it in our DevForce resource Center.
 
Silvio.
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2011 at 3:57pm
Try this, go into your Model.IB.Designer.cs file and replace it with this

<#@ template  language="C#" debug="true" hostSpecific="true" #>
<#@ output extension=".ReadMe" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ Assembly Name="IdeaBlade.VisualStudio.DTE.dll" #>
<#@ Assembly Name="IdeaBlade.VisualStudio.OM.CodeGenerator.dll" #>
<#@ Assembly Name="IdeaBlade.EntityModel.Edm.Metadata.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="IdeaBlade.VisualStudio.DTE" #>
<#@ import namespace="IdeaBlade.VisualStudio.OM.CodeGenerator" #>
<#@ import namespace="IdeaBlade.EntityModel.Edm.Metadata" #>
<#
// Source for this file located at: C:\Users\Mark\AppData\Local\Microsoft\VisualStudio\10.0\Extensions\IdeaBlade, Inc\IdeaBlade OM Designer Extension\6.0.8.1\DomainModelTemplate.tt
// YourEdmxName.edmx  <--- This is needed so that "Transform Related Text Templates On Save" works correctly.
var template = new NewTemplate(this);
template.Generate();
#>
<#+ 
public class NewTemplate : DomainModelTemplate
    {
        public NewTemplate(Microsoft.VisualStudio.TextTemplating.TextTransformation textTransformation) : base(textTransformation)
        {
        }

        protected override void WriteAttribute(string attribute, bool isInCSharpFormat = true)
        {
            var newAttribute = attribute.Replace("IbVal.StringLengthVerifier", "MyStringLengthVerifier");
            base.WriteAttribute(newAttribute, isInCSharpFormat);
        }

    }
#>

It is very important that you replace "YourEdmxName" with the proper name



Edited by smi-mark - 18-Feb-2011 at 3:59pm
Back to Top
hijaggu View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Sep-2010
Posts: 21
Post Options Post Options   Quote hijaggu Quote  Post ReplyReply Direct Link To This Post Posted: 18-Feb-2011 at 3:30pm

Hi ,

 

 

By default , Ideablade uses StringLengthVerifier in auto generated code for entity model like below ,

 

 /// <summary>Gets or sets the Address2. </summary>
    [
Bindable(trueBindingDirection.TwoWay)]
    [
Editable(true)]
    [
Display(Name="Address2", AutoGenerateField=true)]
    [IbVal.
StringLengthVerifier(MaxValue=50, IsRequired=true, ErrorMessageResourceName="Doctor_Address2")]
    [
DataMember]
    
public string Address2 {
      
get { return PropertyMetadata.Address2.GetValue(this); }
      
set { PropertyMetadata.Address2.SetValue(thisvalue); }
    }
    #endregion Address2 property

 

 Is there a way to supply my own MyStringLengthVerifier so that it generates the code like this.

 

 /// <summary>Gets or sets the Address2. </summary>
    [
Bindable(trueBindingDirection.TwoWay)]
    [
Editable(true)]
    [
Display(Name="Address2", AutoGenerateField=true)]
    [
MyStringLengthVerifier (MaxValue=50, IsRequired=true, ErrorMessageResourceName="Doctor_Address2")]
    [
DataMember]
    
public string Address2 {
      
get { return PropertyMetadata.Address2.GetValue(this); }
      
set { PropertyMetadata.Address2.SetValue(thisvalue); }
    }
    #endregion Address2 property

 

 

 

               We would like to handle IsRequired property differently.   Currently if string column in database table is set to NOT NULL , Ideablade turns IsRequired = true and doesn't allow to assign empty string like '’   which is valid value for NOT NULL fields in database.

 

               So in above case Address2 can be NOT NULL in database table and can still accept empty string '' without  triggering validation.

 

 - Jignesh Suthar

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down