DateTime Default not working correctly

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

DateTime Default not working correctly

Post by OutOfTouch6947 » Fri 05 May 2017 21:52

No matter what I try as the default now(), localtimestamp, etc... I always see, 0001-01-01 00:00:00 as the value when the record is inserted and I am not providing the value. I am not sure if it is the ED or me and my lack of postgresql knowledge but this is a pretty easy and basic thing to do in the other database I came from.
Here is an example of one of the ways I have tried to default the value.

Code: Select all

ALTER TABLE "SalesOrderHeader" ALTER COLUMN "CreatedDate"  SET DEFAULT localtimestamp;

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Wed 10 May 2017 18:57

Does anyone have any ideas on what is causing this?

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

Re: DateTime Default not working correctly

Post by Shalex » Thu 11 May 2017 09:52

Did you set AutoGeneratedValue=True and Auto-Sync=OnInsert for your CreatedDate property in the *.lqml model?

If this doesn't help, please give us the following information:
1) enable the dbMonitor tool and specify the exact SQL statement sent to PostgreSQL Server when the record is inserted
2) send us a small test project with the corresponding DDL/DML script for reproducing the issue in our environment

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Thu 11 May 2017 14:38

I took CreatedDate out of the model and I get the same result. So is it even possible to still be the model that is causing the issue?

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

Re: DateTime Default not working correctly

Post by Shalex » Thu 11 May 2017 16:57

Please give us the following information:
1) enable the dbMonitor tool and specify the exact SQL statement sent to PostgreSQL Server when the record is inserted
2) send us a small test project with the corresponding DDL/DML script for reproducing the issue in our environment

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Thu 11 May 2017 17:28

Where do I load in code PgSqlMonitor in MVC application?

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Mon 15 May 2017 13:57

I can't provide you what you asked, unless you tell me where to load in code PgSqlMonitor in MVC application?

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

Re: DateTime Default not working correctly

Post by Shalex » Wed 17 May 2017 09:07

Please open your \WebApplication\Global.asax and create the PgSqlMonitor instance:

Code: Select all

    public class MvcApplication : System.Web.HttpApplication
    {
        PgSqlMonitor monitor;

        protected void Application_Start()
        {
            monitor = new PgSqlMonitor() { IsActive = true };

            // ....
        }
    }

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Thu 18 May 2017 15:28

You can see that I removed the CreatedDate from the model for this table as a test to see, if it would default correctly, and it still does not, but it also is not in this insert statement.

Code: Select all

INSERT INTO public."SalesOrderHeader" ("CustomerId", "OrderNumber", "SalesRepId", "SalesRepName", "SourceCode", "Date", "SubTotal", "Discount", "SalesTaxRate", "SalesTaxAmount", "ShippingTotal", "OrderTotal", "PaymentMethodTypeId", "PromoCode", "CreatedBy", "ModifiedBy", "Exported", "Notes") VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18) RETURNING "SalesOrderHeaderId"

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Thu 18 May 2017 15:33

Correction I now see the correct value being inserted into the table for the CreatedDate, I am going to add it back to the model and run dbmonitor again and see if it works correctly.
OutOfTouch6947 wrote:You can see that I removed the CreatedDate from the model for this table as a test to see, if it would default correctly, and it still does not, but it also is not in this insert statement.

Code: Select all

INSERT INTO public."SalesOrderHeader" ("CustomerId", "OrderNumber", "SalesRepId", "SalesRepName", "SourceCode", "Date", "SubTotal", "Discount", "SalesTaxRate", "SalesTaxAmount", "ShippingTotal", "OrderTotal", "PaymentMethodTypeId", "PromoCode", "CreatedBy", "ModifiedBy", "Exported", "Notes") VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18) RETURNING "SalesOrderHeaderId"

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Thu 18 May 2017 17:35

I just added it back to the model and again I don't see the correct datetime being inserted, I am going to run DBMONITOR again and post the insert statement.
OutOfTouch6947 wrote:Correction I now see the correct value being inserted into the table for the CreatedDate, I am going to add it back to the model and run dbmonitor again and see if it works correctly.
OutOfTouch6947 wrote:You can see that I removed the CreatedDate from the model for this table as a test to see, if it would default correctly, and it still does not, but it also is not in this insert statement.

Code: Select all

INSERT INTO public."SalesOrderHeader" ("CustomerId", "OrderNumber", "SalesRepId", "SalesRepName", "SourceCode", "Date", "SubTotal", "Discount", "SalesTaxRate", "SalesTaxAmount", "ShippingTotal", "OrderTotal", "PaymentMethodTypeId", "PromoCode", "CreatedBy", "ModifiedBy", "Exported", "Notes") VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18) RETURNING "SalesOrderHeaderId"

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Thu 18 May 2017 17:43

Here is the insert statement with the CreatedDate and ModifiedDate added back into the models and the values are not defaulting correctly in the backend, so the model must be passin in some junk value.

Code: Select all

INSERT INTO public."SalesOrderHeader" ("CustomerId", "OrderNumber", "SalesRepId", "SalesRepName", "SourceCode", "Date", "SubTotal", "Discount", "SalesTaxRate", "SalesTaxAmount", "ShippingTotal", "OrderTotal", "PaymentMethodTypeId", "PromoCode", "CreatedDate", "CreatedBy", "ModifiedDate", "ModifiedBy", "Exported", "Notes") VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18, :p19, :p20) RETURNING "SalesOrderHeaderId"
OutOfTouch6947 wrote:I just added it back to the model and again I don't see the correct datetime being inserted, I am going to run DBMONITOR again and post the insert statement.
OutOfTouch6947 wrote:Correction I now see the correct value being inserted into the table for the CreatedDate, I am going to add it back to the model and run dbmonitor again and see if it works correctly.
OutOfTouch6947 wrote:You can see that I removed the CreatedDate from the model for this table as a test to see, if it would default correctly, and it still does not, but it also is not in this insert statement.

Code: Select all

INSERT INTO public."SalesOrderHeader" ("CustomerId", "OrderNumber", "SalesRepId", "SalesRepName", "SourceCode", "Date", "SubTotal", "Discount", "SalesTaxRate", "SalesTaxAmount", "ShippingTotal", "OrderTotal", "PaymentMethodTypeId", "PromoCode", "CreatedBy", "ModifiedBy", "Exported", "Notes") VALUES (:p1, :p2, :p3, :p4, :p5, :p6, :p7, :p8, :p9, :p10, :p11, :p12, :p13, :p14, :p15, :p16, :p17, :p18) RETURNING "SalesOrderHeaderId"

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Thu 18 May 2017 18:20

Ok so I determined as soon as I remove it from the model it uses the default constraint correctly. When it is in the model I don't set any value for it not even null. Is that what is causing the problem?

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

Re: DateTime Default not working correctly

Post by Shalex » Fri 19 May 2017 11:55

OutOfTouch6947 wrote:Here is the insert statement with the CreatedDate and ModifiedDate added back into the models and the values are not defaulting correctly in the backend, so the model must be passin in some junk value. [...]
1. Did you set the following attributes for your CreatedDate and ModifiedDate properties in *.lqml?
CreatedDate: AutoGeneratedValue=True, Auto-Sync=OnInsert
ModifiedDate: AutoGeneratedValue=True, Auto-Sync=OnUpdate

2. Specify (via dbMonitor) the values of parameters used in the INSERT statement for "CreatedDate" and "ModifiedDate" columns.

3. Send us a small test project with the corresponding DDL/DML script for reproducing the issue in our environment.

OutOfTouch6947
Posts: 79
Joined: Tue 02 Jun 2015 18:22

Re: DateTime Default not working correctly

Post by OutOfTouch6947 » Fri 19 May 2017 18:45

I didn't set the AutoGeneratedValue or Auto-Snc.
Where can I find an detailed explanation of AutoSync Mode?
Shalex wrote:
OutOfTouch6947 wrote:Here is the insert statement with the CreatedDate and ModifiedDate added back into the models and the values are not defaulting correctly in the backend, so the model must be passin in some junk value. [...]
1. Did you set the following attributes for your CreatedDate and ModifiedDate properties in *.lqml?
CreatedDate: AutoGeneratedValue=True, Auto-Sync=OnInsert
ModifiedDate: AutoGeneratedValue=True, Auto-Sync=OnUpdate

2. Specify (via dbMonitor) the values of parameters used in the INSERT statement for "CreatedDate" and "ModifiedDate" columns.

3. Send us a small test project with the corresponding DDL/DML script for reproducing the issue in our environment.

Post Reply