Adapter.SaveEntity error in generated query

Posts   
 
    
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 11-Mar-2005 16:10:07   

Hi,

I have an entity downloaded from the database. I change a property value, and use the adapter.SaveEntity(MyEntity), that succeds.

When the downloaded entity has parent entity, I get an ORMQueryExcecution error:

Message "An exception was caught during the execution of an action query: Line 1: Incorrect syntax near ')'".

StackTrace "at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute()"

QueryExecuted "Query: INSERT INTO [order].[dbo].[project] () VALUES ();SELECT @Id=SCOPE_IDENTITY()

Parameters: @Id : Int32. Direction: Output.

I think on should generate an update query. disappointed

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Mar-2005 16:42:23   

It does create an update query, but there are no fields changed in the entity though it does have an identity field so the query engine proceeds with the save. Could you check please if there are any fields changed in the related entity? Thanks.

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 11-Mar-2005 23:44:46   

Hi Frans,

I change the property of the order, but not change the project before save.

MyOrder.Inact=True

MyAdapter.SaveEntity(MyOrder)

When debug, the IsNew property is false, and the IsDirty is true.

The same code works well, if I set the Inact property of the Project, that hasen't parent object.

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Mar-2005 12:36:38   

Gabor wrote:

Hi Frans,

I change the property of the order, but not change the project before save.

MyOrder.Inact=True

MyAdapter.SaveEntity(MyOrder)

When debug, the IsNew property is false, and the IsDirty is true.

The same code works well, if I set the Inact property of the Project, that hasen't parent object. Gabor

The problem is the project entity. I assume Order - Project is an m:1 relation? (Order has an FK to Project) ? If so, this means that if myOrder.Project = myProject, and you don't set any properties of myProject, that entity is saved first, but that doesn't work, as there is no field set and you get the error you received in your first posting.

Perhaps for clarification, could you paste some code which causes the problem? Thanks.

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 17-Mar-2005 11:57:33   

Frans,

Yes beetwen project and order is 1:m relationship, and I really don't set any property in the project, because nothing changed in it.

So, how can I save then the many part of the relation ie. the order?

In my app. i bound the order collection to the grid control, and change only his property.

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 17-Mar-2005 13:25:46   

Do you add in the grid / via the grid a new project entity somewhere? As that's what's happening: there is a new project entity in the graph which is saved as well, which results in that INSERT query and it fails because it's empty (i.e.: it has an identity column, but no other fields are set)

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 17-Mar-2005 18:13:06   

Thanks Frans,

I add to the grid an entity collection of the orders of different, but existing projects.

All project has the same order date.

When I add a new order via the grid, I set the projectID property of the order.

So, it isn't enough to set the propjectID property of the order, and have to add the appropriate project object to the order too?

Thanks in advance

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 18-Mar-2005 11:14:33   

Gabor wrote:

Thanks Frans,

I add to the grid an entity collection of the orders of different, but existing projects.

All project has the same order date.

When I add a new order via the grid, I set the projectID property of the order.

So, it isn't enough to set the propjectID property of the order, and have to add the appropriate project object to the order too?

Thanks in advance

Gabor

No, that should be enough. Though the new order will somehow get a new project assigned to it. As you use adapter, you should be able to check if newOrder.Project is null before the save. It should be null. (just for testing). Your error comes from the fact that there is a project entity without changed fields with IsNew is true which is saved together with the orders.

Frans Bouma | Lead developer LLBLGen Pro