Trouble creating new entity

Posts   
 
    
bot2600
User
Posts: 17
Joined: 12-Mar-2006
# Posted on: 12-Mar-2006 08:16:44   

I am using myentity = new myentity() on a table with an identity field as the primary key. This is updating the 0 row instead of creating a new entity. I am confused confused

Bob

I am using 1.0.2004.1 Final as the version. Oh, and .IsNew is saying true.

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 12-Mar-2006 09:01:35   

bot2600 wrote:

I am using myentity = new myentity() on a table with an identity field as the primary key. This is updating the 0 row instead of creating a new entity. I am confused confused

Bob

I am using 1.0.2004.1 Final as the version. Oh, and .IsNew is saying true.

It's best is you post the actualy code you have written. That way we can help you correct the problem.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Mar-2006 11:18:37   

Do you actually set a field to a value in the entity?

Frans Bouma | Lead developer LLBLGen Pro
bot2600
User
Posts: 17
Joined: 12-Mar-2006
# Posted on: 12-Mar-2006 17:42:42   

Hi, thank you for the response. There really isnt any other code than that. The PK ID column works normal except on that one table, which has a row with an identity of 0.

On that table, getting the entity returns a primary key of 0, and writing to the fields and saving the entity writes to the 0 row of the table. The same code is used on other tables whose identity counter starts at 1 and behaves as expected (same as far as I can see anyhow). Once again, thank you for the quick response.

Bob

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Mar-2006 18:52:31   

I think that you shouldn't start identity PKs with 0.

Frans Bouma | Lead developer LLBLGen Pro
bot2600
User
Posts: 17
Joined: 12-Mar-2006
# Posted on: 12-Mar-2006 20:37:48   

I dont disagree with that statement, but unfortunantly I dont have any control over the database, and other apps rely on the 0 entry. I guess I'll use a stored proc to insert the new entity. Thanks for the help.

Bob

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Mar-2006 20:52:09   

It still would be great to see some real code, as inserting an entity should just work in that table, despite the fact that there's an entity with ID=0.

Frans Bouma | Lead developer LLBLGen Pro
bot2600
User
Posts: 17
Joined: 12-Mar-2006
# Posted on: 12-Mar-2006 21:42:36   

As expected, it was user error. It seems the ProfileProvider was initializing the key since it was an int in the web.config. Sorry to have doubted your code wink

Bob