locked
Helping the 'Read-only-ness' of identity columns RRS feed

  • Question

  • User1450188179 posted


    I am exploring the option to automate the 'Read-Only-ness' of Identity Columns for insert mode.
    Eg NorthWind - ListDetails form browsing the Employees Table.
    In the details view at the bottom of the page, updating the Employee correctly has the EmployeeID Column showing as read only, however inserting a new employee has the EmployeeID column in edit mode requiring the user to enter a nonsense value.


    I have traced the lack of metadata information back to the Entity Framwork and a disjoint between the storage and conceptual models. I have been trying to see if there is a way to have metadata passed down to the client or manipulating property setters accessibility but no having much luck once back at the client. See my post in the EF forum: http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=4013557&SiteID=1

    So I tried having a private setter, as this is the only thing I can control as far as I can see, but I get deserialization problems with a private setter:

    ...

    [InvalidOperationException: The closed type System.Int32 does not have a corresponding EmployeeID settable property.]
       System.Data.Services.Client.ClientProperty.SetValue(Object instance, Object value, String propertyName, Boolean allowAdd) +270636
       System.Data.Services.Client.MaterializeAtom.ReadNext(ClientType currentType, Type expectedType, AtomParseState atom, EntityStates& entityState, Object& currentValue) +5056
       System.Data.Services.Client.MaterializeAtom.MoveNext() +544
       System.Web.DynamicData.Misc.FillListItemCollection(MetaTable table, ListItemCollection listItemCollection) +649
       System.Web.DynamicData.ForeignKeyFilterDelegate.PopulateListControl(ListControl listControl) +25
       System.Web.DynamicData.FilterUserControlBase.PopulateListControl(ListControl listControl) +25

    ...

    Does anyone have any suggestions is this area?


    I would like to aim for the equilant of displaying a read-only 'Auto' or 'New' etc when you do inserts into applications such as Access etc, rather than confusing the user with what to enter.
    Also I would like to avoid having to alter every Client side entity myself as I think this is a generic enough issue to need a generic solution.
    I can't see any way around this in a generic fashion without doing some very unreliable hack eg ColumnName.EndsWith("ID")... which aready won't work for some classes I have.

    I can see this is not strictly a Dynamic Data problem and that it goes through the DataService and to the EF, but since EF and DataServices are baked into SP1 then I somehow have find a work around further down the stack.

    Any help or thoughts appreciated.


    Cheers
    Simon

    Sunday, October 19, 2008 7:30 PM

Answers

  • User1641955678 posted

    Hi Simon,

    Since you're using a custom Model provider for Astoria, you may want to try turning on the IsGenerated flag on your ColumnProvider.  I think this will do what you want.

    thanks,
    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 20, 2008 12:06 AM

All replies

  • User1641955678 posted

    Hi Simon,

    Since you're using a custom Model provider for Astoria, you may want to try turning on the IsGenerated flag on your ColumnProvider.  I think this will do what you want.

    thanks,
    David

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 20, 2008 12:06 AM
  • User1450188179 posted

     Fantastic, Thanks David,

    I see in the provider the constructor which acknowledges this issue:

    public DataServiceColumnProvider(TableProvider table, PropertyInfo prop, bool isKey)
                : base(table) {
                _prop = prop;
                Name = _prop.Name;
                ColumnType = _prop.PropertyType;
                IsPrimaryKey = isKey;
                IsSortable = true;
                IsGenerated = false; // We don't have a way of knowing this...could be an issue
                IsForeignKeyComponent = false; // No FKs in Astoria
                IsCustomProperty = false; // All properties are considered part of the contract in Astoria client
                Nullable = DataServiceUtilities.IsNullableType(ColumnType);
            }

     

    So I  now need a smart way to do this. Perhaps for the Short term I will create a custom attribute to map to this. In the long term it would be great if this type of info came in the metadata from the EF->DataService->Proxy->DD :).

    Cheers

    Simon

    Monday, October 20, 2008 7:15 PM