Postgresql Target Per Entity Issue

Posts   
 
    
18237
User
Posts: 3
Joined: 30-Mar-2024
# Posted on: 30-Mar-2024 08:33:13   

I am using LLBLGen Pro Version: 5.11 (5.11.2) RTM SD.LLBLGen.Pro.DQE.PostgreSql : 5.11.1 SD.LLBLGen.Pro.ORMSupportClasses : 5.11.1

In a Target Per Entity project, when saving an entity (see the CODE block below) I am receiving the following error (see the EXCEPTION below):

Seems that is trying to query the parent table: - using: "public.my_party" - instead of: "public"."my_party" which is what Postgresql uses

CODE:

using (var db = new DataAccessAdapter(cn))
{
    var org = new MyOrganizationEntity();
    org.Subtype = "O";
    org.CreatedBy = "dchang";
    org.CreatedOn = DateTime.Now;
    org.CreditRatingTypeId = 1;
    org.Name = "Changsoft, LLC";
    org.OrganizationSubtype = 1;
    db.SaveEntity(org);
}

EXCEPTION:

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException
  HResult=0x80131500
  Message=An exception was caught during the execution of an action query: 42P01: relation "public.my_party" does not exist

POSITION: 13. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
  Source=SD.LLBLGen.Pro.ORMSupportClasses
  StackTrace:
   at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute()
   at SD.LLBLGen.Pro.ORMSupportClasses.BatchActionQuery.Execute()
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.ExecuteActionQuery(IActionQuery queryToExecute)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.<PersistQueue>b__57_0(IActionQuery q)
   at SD.LLBLGen.Pro.ORMSupportClasses.ActionQueryController.ExecuteElements(List`1 elementsToRun)
   at SD.LLBLGen.Pro.ORMSupportClasses.ActionQueryController.Execute(ActionQueueElement`1 actionQueueElement, IActionQuery query, Type typeOfNextElement)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.PersistQueue(List`1 queueToPersist, Boolean insertActions)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.<>n__18(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.<>c__DisplayClass19_0.<SaveEntity>b__0()
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteWithActiveRecoveryStrategy[T](Func`1 toExecute)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterCore.SaveEntity(IEntity2 entityToSave)
   at DataAccessTest.Tests.Test1() in F:\Changsoft\src\tests\unit\dataaccess\DataAccessTest\UnitTest1.cs:line 32
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
PostgresException: 42P01: relation "public.my_party" does not exist

POSITION: 13
Attachments
Filename File size Added on Approval
Model.png 20,548 30-Mar-2024 08:57.10 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 30-Mar-2024 13:18:01   

I can't reproduce it, names are properly wrapped with "", e.g.

INSERT 
INTO
    "public"
    ."products" ("productid", "productname", "reorderlevel") 
VALUES
    (nextval('"public"."products_productid_seq"'), :p2, (SELECT
        COUNT("public"."products"."productid") AS "Productid" 
    FROM
        "public"."products")) RETURNING "productid"

from test:

[Test]
public void InsertWithExpressionTest()
{
    using(var adapter = new DataAccessAdapter())
    {
        var productCount = adapter.GetDbCount(new EntityCollection<ProductsEntity>(), null);
        var product = new ProductsEntity() { Productname = "Foo" };
        product.Fields[(int)ProductsFieldIndex.Reorderlevel].ExpressionToApply = new ScalarQueryExpression(ProductsFields.Productid.Count());
        try
        {
            Assert.IsTrue(adapter.SaveEntity(product, true));
            Assert.AreEqual(productCount, product.Reorderlevel);
            Assert.IsTrue(adapter.DeleteEntity(product));
        }
        catch
        {
            adapter.DeleteEntity(product);
        }
    }
}

Please check which query is produced and executed, using either tracing (https://www.llblgen.com/Documentation/5.11/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_troubleshootingdebugging.htm) or ORM Profiler (Free for users with an active subscription, see on our website My Account -> downloads -> ORM Profiler (at the top, right) https://www.llblgen.com/Pages/ormprofiler.aspx

Frans Bouma | Lead developer LLBLGen Pro
18237
User
Posts: 3
Joined: 30-Mar-2024
# Posted on: 31-Mar-2024 10:03:20   

I was able to do the trace and figure out the issue. Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 01-Apr-2024 08:15:12   

18237 wrote:

I was able to do the trace and figure out the issue. Thanks

For my understanding, what was the issue? So if other people run into this we have a better answer simple_smile

Frans Bouma | Lead developer LLBLGen Pro
18237
User
Posts: 3
Joined: 30-Mar-2024
# Posted on: 01-Apr-2024 13:29:08   

It was picking up the wrong connection string from the configuration. Therefore it was connecting to a different database. I should have concluded that when the "Relation not found message" came.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 02-Apr-2024 08:16:54   

Ah right, glad it's solved! simple_smile

Frans Bouma | Lead developer LLBLGen Pro