Update collection with prefetch path

Posts   
 
    
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 15-Apr-2005 00:27:18   

Hi,

I have two tables with one-tomany relation.

I fetched the tables with prefetchPath. Used a filter on the one side table, and a filter expression on the many side table, so that every parent table has only one prefetched record in the child table.

I set the property of the entity object, and in the child object.

The SaveEntityCollection(col, false, true) doesnt raise exception, but on updates nothing in the database.

What is the mistake?

Thanks

Gabor

Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 15-Apr-2005 08:14:42   

Please ignore it smile

Thanks

Gabor

Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 15-Apr-2005 08:28:33   

Frans,

I have two tables with 1-m relation (project-account), and want to update directly the dueDate fields in both tables.

I used the following code:

     Dim adp As New DataAccessAdapter

    Dim project As New ProjectEntity(ID)
    Dim AccountCol As New EntityCollection
    Dim Account As AccountEntity

    Dim bucket As New RelationPredicateBucket
    bucket = project.GetRelationInfoAccountCol

    AccountCol = project.AccountCol

    With project
        .IsNew = False
        .dueDate = dueDate
    End With

    For Each Account In AccountCol
        Account.dueDate= dueDate
    Next

    Try
        adp.UpdateEntitiesDirectly(project, bucket)
    Catch ex As Exception
        Debug.WriteLine(ex.Message)
        Throw ex
    Finally
        adp.Dispose()
    End Try

But get the following exception:

An exception was caught during the execution of an action query: The column prefix 'AccountProject.dbo.Account' does not match with a table name or alias name used in the query.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

The Stack Trace smile

StackTrace  "   at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute()

at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteActionQuery(IActionQuery queryToExecute) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.UpdateEntitiesDirectly(IEntity2 entityWithNewValues, IRelationPredicateBucket filterBucket) at BLL.queryMan.SetFizetve(Int32 ID, DateTime elszamolasDate, DateTime fizetveDate, Boolean IsProject) in C:\VB7projectek\MunkaElszamolo\BLL\queryMan.vb:line 547" String

Thanks in advance

"The hardest task; to find the simplest solution" disappointed

Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 15-Apr-2005 09:59:06   

The above solution is obviously wrong. simple_smile

To ask more simply:

Is it any way, to update child table fieds directly, knowing only the parent table's row primary key?

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Apr-2005 10:09:03   

Gabor wrote:

The above solution is obviously wrong. simple_smile

To ask more simply:

Is it any way, to update child table fieds directly, knowing only the parent table's row primary key?

The parent's table PK is the same as the FK in the child simple_smile . So you can just filter on the FK field(s) in the child using the PK value of the parent for you direct update in the database.

For example, if you know the CustomerID of a customer and you want to update all that customer's orders, you can of course do:

update order SET ...

WHERE customerID IN (select customerid from customer where customerid = @customerid)

but because order and customer are related, the PK of customer is the FK in order, so you can just do:

update order SET ...

WHERE customerID = @customerid) simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 15-Apr-2005 10:33:13   

Thanks Frans,

Doing this simple in SQL, but how can I achieve the same result with LLBLGen, not fetching the objects, but update the parent and related child table fields?

I know only the parent tbl's row primary key.

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Apr-2005 10:52:00   

For simple update child set field = value where child.fkfield = pkfieldOfParent

updates, please see: Best practises: How do I? -> How do I update a series of entities directly in the database?

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 15-Apr-2005 12:28:58   

Thanks Frans,

It works well, when I update the child table.

My question is:

There is a way to update the parent table's one record, and the child table's records altogether with one roundtrip?

I tried to add a relation from child to the parent in the bucket, but doesn't work.

Thanks in advance

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 16-Apr-2005 12:06:21   

Gabor wrote:

Thanks Frans,

It works well, when I update the child table.

My question is:

There is a way to update the parent table's one record, and the child table's records altogether with one roundtrip?

I tried to add a relation from child to the parent in the bucket, but doesn't work.

Updates in 2 different tables, requires two different update calls, so you can't do that in 1 go.

Frans Bouma | Lead developer LLBLGen Pro