none
Using Defaults values in LinqToSql?? RRS feed

  • Question

  • Hi... I have a table in SQL with Default values like this
    Order = Identity
    OrderRequested = GetDate()
    OrderStatus = 1
    Some other columns = Manualy Computed

    Of course and as a good practice all columns are NonNullables

    In my dbml i put the OrderRequested as Auto Generated value
    because i want to obtain the server date. For OrderStatus i
    set by default to 1 (thats is the first state of an order).
    Order is identity and automatically qualify to be Auto Generated

    When i want to insert data using LinqToSql all works perfect,
    however when i try to update OrderStatus i have the fkn
    Error: OrderStatus is autogenerated and not suport update (or
    something like that)

    How can i update my OrderStatus?? i dont want to use code behind
    OnCreate command cause thats a poor solution and to complex
    to mainteinance.

    Friday, November 18, 2011 9:20 PM

Answers

  • Hi Arelly,

    I have tested on my computer, it really throw the exception when I call submitchanges method, but if I use ado.net instead of LINQ to SQL, it works well. After researching, I find a case similar with yours, you can refer to its answer. Please click here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, November 23, 2011 5:43 AM
    Moderator

All replies

  • Hi Arelly,

    Based on your post, I didn't find you have set the OrderStatus as autogenerated, in order to help you more effectively, could you please provide the code?

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 22, 2011 2:35 AM
    Moderator
  • Yes i mark OrderStatus as AutoGenerated...

    When i create a new row all works perfect. Order gets new number automatically, my OrderRequested takes the serverdate automatically and the OrderStatus are set to 1 automatically. However when i try to update my OrderStatus i have the message of error.

    I dont know why Autogenerated columns supports only insertions but not update changes.

    Let me put some code for share

    Tuesday, November 22, 2011 5:36 PM
  • Hi Arelly,

    I have tested on my computer, it really throw the exception when I call submitchanges method, but if I use ado.net instead of LINQ to SQL, it works well. After researching, I find a case similar with yours, you can refer to its answer. Please click here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Wednesday, November 23, 2011 5:43 AM
    Moderator
  • I am just guessing here:

    open your dbml, open the property window, click on the field OrderStatus in the dbml, and in the property window change "Update Check" to Never.


    Wednesday, November 23, 2011 9:17 AM