apply attribute for <DisplayFormat(ConvertEmptyStringToNull:=False)> in the edml model

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
nhill383
Posts: 13
Joined: Sun 26 Apr 2015 21:43

apply attribute for <DisplayFormat(ConvertEmptyStringToNull:=False)> in the edml model

Post by nhill383 » Tue 05 May 2015 20:27

Hi,

I have posted a sample project, please take a look at that.

DDL SQL for the sample
CREATE TABLE customers
(
cus_pk serial NOT NULL,
cus_name character varying NOT NULL DEFAULT ''::character varying,
CONSTRAINT customers_pkey PRIMARY KEY (cus_pk)
)

as per above DDL i have a text field that is defined as NOT NULL default ''. I have been trying to get a working solution to save teh data back to the database.

I have implemented metadata approach as follows

Code: Select all

 Public Class CustomerMetaData

        <Editable(False)>
        <Display(Name:="ID", description:="Unique Identifier")>
        Property CusPk() As Integer

        <Display(Name:="Customer Name (MetaData)", description:="Full name of customer")>
        <DisplayFormat(ConvertEmptyStringToNull:=False)>
        Property CusName() As String = ""


    End Class

    <MetadataType(GetType(CustomerMetaData))>
    Partial Public Class Customer

    End Class
This works fine

I would like the option of using the attributes property of the entityproperty, this is what i am trying to make work.

to reproduce the problem.
make sure metadata code is commented out
run the sample
navigate to host:port/customers/create
click create without entering anything in the customer name textbox

an error is thrown with validation error of customer name is required. the problem only happens with a blank customer name. if you enter some text it will create fine.

What do i need to to do to achieve the same functionality as the metadata approach but just using the attributes collection within the CusName entitproperty.

Why do i want to do this, well partly because it is bugging me now, and also i am just starting out, not sure if i would prefer the approach of using the designer rather than maintaining classes myself. not sure, but i am pretty sure it would teach me something to understand how to get it working properly

thanks

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

Re: apply attribute for <DisplayFormat(ConvertEmptyStringToNull:=False)> in the edml model

Post by Shalex » Thu 07 May 2015 07:46

Please select your project in Solution Explorer and press the Show All Files button (located in the Solution Explorer's Toolbar). After this, you will see the *.vb files generated by *.edml model. Open DataModel1.Customer.vb, it includes

Code: Select all

<DisplayFormat> _
Public Overridable Property CusName() As String = ""
instead of

Code: Select all

<DisplayFormat(ConvertEmptyStringToNull:=False)> _
Public Overridable Property CusName() As String = ""
The reason of the problem is that Entity Developer considers False is a default value of ConvertEmptyStringToNull (and does not generate it explicitly). That is incorrect, because the default value of ConvertEmptyStringToNull is True. We will investigate the problem with the Entity Developer behaviour and notify you about the result.

A temporary workaround.
Open *.edml, navigate to Tools > Entity Developer > Model Explorer > Templates, select DbContext, press F4 (Properties), set Generate Partial Class=True, remove DataModel1.Customer.vb in Solution Explorer, save the model. Now you have two *.vb for the Customer class:
* DataModel1.Customer.Generated.vb -> it will be regenerated each time you save the model
* DataModel1.Customer.vb -> here you can add your code which will not be overwritten by the designer
Open *.edml again, delete the CusName property from CSDL (but it will be preserved in SSDL). Save *.edml. Open DataModel1.Customer.vb and define the CusName property with needed attributes:

Code: Select all

    Partial Public Class Customer
        <Display(Name:="Customer Name (MetaData)", description:="Full name of customer")>
        <DisplayFormat(ConvertEmptyStringToNull:=False)>
        Property CusName() As String = ""
    End Class
Now it should work.

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

Re: apply attribute for <DisplayFormat(ConvertEmptyStringToNull:=False)> in the edml model

Post by Shalex » Wed 27 May 2015 09:16

The bug with detecting the default values of attributes added via the Attributes menu is fixed.

With the new build, you should remove and readd the reference to System.ComponentModel.DataAnnotations.dll via the Attributes menu of Entity Developer.

We will notify you when the corresponding build of dotConnect for PostgreSQL is available for download.

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

Re: apply attribute for <DisplayFormat(ConvertEmptyStringToNull:=False)> in the edml model

Post by Shalex » Fri 29 May 2015 07:29

New build of dotConnect for PostgreSQL 7.3.422 is available for download now.

It can be downloaded from http://www.devart.com/entitydeveloper/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=3&t=31862.

Post Reply