Property Required (not null) allow sapce

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
figueiredorj
Posts: 36
Joined: Fri 12 Apr 2013 19:05

Property Required (not null) allow sapce

Post by figueiredorj » Tue 05 Jan 2016 15:04

Hi,

I am working on a database first environment where there is a specific requirement.
Back to start when there was no value to fill the default value would be a string of x cardinality empty spaces.

However when using ef with becomes kinf of odd because NotNull/Required treats empty spaces as a null value.

I needed being able to add on dbcontext the required attribute for this specific properties as

Code: Select all

  [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)] 
How can I achieve this?

thanks

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Property Required (not null) allow sapce

Post by Shalex » Tue 05 Jan 2016 15:23

There are two ways to add attributes via interface of Entity Developer:

1. Validation Framework
a) open Tools > Entity Developer > Model Explorer > the Templates node, select your template (e.g., DbContext), navigate to its properties:
-> set the Validation Framework property (e.g., to "Data Annotations")
-> open Validation Error Messages and specify the text for Required Message
b) set, for example, Validate Required=True for a particular class property

2. Custom Attributes
a) navigate to Model > Settings > Attributes > select the assembly with the needed attributes and make sure that the needed attributes are checked in the window below, press OK
b) select the needed attribute in the Attributes collection of a particular class property

The [1] approach is easier to use. If [1] doesn't cover your needs, you can add any attributes in the way which is described in [2].

figueiredorj
Posts: 36
Joined: Fri 12 Apr 2013 19:05

Re: Property Required (not null) allow sapce

Post by figueiredorj » Tue 05 Jan 2016 18:03

Hi Shalex,

I am aware of both options.
However you already have on your tool the definition of required on your property editor, which generates previous code.

I want to know how I can tweak it in order of achiveing the desired option of allowing empty spaces.

ED generates

Code: Select all

[System.ComponentModel.DataAnnotations.Required()]
where I would like the option of being able to generate

Code: Select all

[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)
note param in ctor AllowEmptyStrings = true

thanks

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Property Required (not null) allow sapce

Post by Shalex » Wed 06 Jan 2016 15:01

Predefined templates generate the Required attribute without parameters because this suits all validation frameworks.

Please select all classes in Model Explorer (holding Shift select the first and the last one) and set the Required attribute with AllowEmptyStrings = true for all your classes simultaneously.

A similar issue was discussed at http://forums.devart.com/viewtopic.php?f=32&t=31882.

Post Reply