none
LINQ to SQL - Make a field read-only after it has been set RRS feed

  • Question

  • Hello,

    I have a boolean field (StockItem ) on my L2S object to track whether or not an item should be inventoried. The field, represented on the form as a checkbox, is not required, but if the user saves the item with StockItem = true, then the StockItem field should become read-only (locked with it's true value). I know how to accomplish this on the UI, but I was hoping I could do it at the class level and the bound checkbox's enabled property would be set automatically. Any idea how I can accomplish this? I presume I can do it in my partial class, but not sure how:


    Partial Class Item

        Private Sub OnLoaded()
            If Me. StockItem Then
                'How do I set StockItem to read-only?

            End If
        End Sub
    End Class
    Thursday, March 5, 2009 6:03 PM

All replies

  •  The properties provided by LINQ do not allow overrides. My initial thoughts were you could override the property and customize the GET/SET logic. Unfortunately you cant do this and changing the actual code would defeat the purpose of code generation. I suggest the simplest solution is to implement your own logic as this conditional behaviour is part of your system and unrelated to the data itself. I would suggest adding a bit flag or simple not null check before updating the value. You should be able to abstract this in your own code.

    Friday, March 6, 2009 1:21 AM