Exception when trying to insert GUID Id

Posts   
 
    
dodyg
User
Posts: 42
Joined: 04-Dec-2014
# Posted on: 08-Nov-2016 10:48:31   

I am on LLBLGen Pro 5.05. Adapter. Vanilla templates.

The Id used to Int. Then I changed it to Guid and sync it with llblgen.


    var res = await Command.DoAsync(async adapter =>
            {
                try
                {
                    await adapter.StartTransactionAsync(System.Data.IsolationLevel.ReadUncommitted, "SaveOrUpdateTask");

                    var e = new PlanTaskEntity
                    {
                        Id = Guid.NewGuid(),
                        TaskTypeId = task.TaskTypeId,
                        StaffId = _staffId,
                        CreatedByUserId = _userId,
                        LastModifiedByUserId = _userId,
                        IsNew = true
                    };

                    await adapter.SaveEntityAsync(e, refetchAfterSave: true);

                    adapter.Commit();

                    return "";
                }
                catch(Exception ex)
                {
                    return ex.Message;
                }
            });

generates

Test Name: Inspection.Core.Tests.Modules.REST.WeeklyManagementTests.BasicInsert Test FullName: Inspection.Core.Tests.Modules.REST.WeeklyManagementTests.BasicInsert Test Source: H:\Repository\Inspection\Trunk\Tests\Inspection.Core.Tests\Modules\REST\WeeklyManagementTests.cs : line 63 Test Outcome: Failed Test Duration: 0:00:02.2

Result StackTrace: at Inspection.Core.Tests.Modules.REST.WeeklyManagementTests.<BasicInsert>d__6.MoveNext() in H:\Repository\Inspection\Trunk\Tests\Inspection.Core.Tests\Modules\REST\WeeklyManagementTests.cs:line 105 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Result Message: An exception was caught during the execution of an action query: Cannot insert the value NULL into column 'Id', table 'Inspection.dbo.PlanTask'; column does not allow nulls. INSERT fails. The statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. Expected: True Actual: False

dodyg
User
Posts: 42
Joined: 04-Dec-2014
# Posted on: 08-Nov-2016 11:14:45   

The following test works just fine


  var res = await Command.DoAsync(async adapter =>
            {
                try
                {
                    await adapter.StartTransactionAsync(System.Data.IsolationLevel.ReadUncommitted, "SaveOrUpdateTask");

                    var e = new RoleEntity
                    {
                        Id = 14000,
                        EnglishName = "hello",
                        ArabicName = "hello ar",
                        IsNew = true
                    };

                    await adapter.SaveEntityAsync(e, refetchAfterSave: true);

                    adapter.Commit();

                    return "";
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            });

            Assert.True(string.IsNullOrWhiteSpace(res), res);

and this one works fine

var res = await Command.DoAsync(async adapter => { try { await adapter.StartTransactionAsync(System.Data.IsolationLevel.ReadUncommitted, "SaveOrUpdateTask");

                var e = new TestTableEntity
                {
                    Id = Guid.NewGuid(),
                    IsNew = true
                };

                await adapter.SaveEntityAsync(e, refetchAfterSave: true);

                adapter.Commit();

                return "";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        });

        Assert.True(string.IsNullOrWhiteSpace(res), res);
dodyg
User
Posts: 42
Joined: 04-Dec-2014
# Posted on: 08-Nov-2016 12:23:50   

I solved this by deleting the Id, map it again, and fix the resulting errors with other entities and derived elements.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 09-Nov-2016 08:23:57   

A guid doesn't get a value by default, unless you give it a default value of NEWSEQUENTIALID() in the database.

Frans Bouma | Lead developer LLBLGen Pro