locked
Adding a record into database... RRS feed

  • Question

  • 1? I have a database 'DateTask' and a 'Tasks' table in it(TaskId, TaskToDo-columns in the table).TaskId is P.K. but autoincrement is set to false.Now i want to add a record into my 'Tasks' table but i don't know what TaskId value should have my record.

    So, please, tell me what can i do. Maybe i can find the greatest value of TaskId in my table and then add the record with TaskID=greatestValue+1; or this is not a good way. Any suggestions??????

     

    2? If i delete some records from my 'Tasks' table(for example i have...   1."Task1", 2."Task2", 3."Task3" and i delete 2."Task2", then i will have 1."Task1", 3."Task3") i will have 'free' TaskId-s, so can i do something to reconstruct my table to be like this`1."Task1", 2."Task3" ?

    Thank You.

    Monday, October 3, 2011 7:45 PM

Answers

  • What Entity Framework version are you using?

    Is there a reason you don't want to use database generated values?

     

    thank you,

    Julia


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by artxach Friday, October 7, 2011 5:51 PM
    Monday, October 3, 2011 10:34 PM
  • Hi artxach,

    1. I don't think get the greatest value+1 is a good way. If there are multi-users in your project, the concurrency issue is here. If you do want to set autoincrement, you can use GUID as your PK.

    2.You delete the record and the add a new record---->You just need update the record.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by artxach Friday, October 7, 2011 5:51 PM
    Wednesday, October 5, 2011 2:35 AM

All replies

  • What Entity Framework version are you using?

    Is there a reason you don't want to use database generated values?

     

    thank you,

    Julia


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by artxach Friday, October 7, 2011 5:51 PM
    Monday, October 3, 2011 10:34 PM
  • Hi artxach,

    1. I don't think get the greatest value+1 is a good way. If there are multi-users in your project, the concurrency issue is here. If you do want to set autoincrement, you can use GUID as your PK.

    2.You delete the record and the add a new record---->You just need update the record.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by artxach Friday, October 7, 2011 5:51 PM
    Wednesday, October 5, 2011 2:35 AM