locked
Can I select columns I want to expose, but hide columns I don't want to expose in Entity Framework? RRS feed

  • Question

  • Hello, I use Entity Framework to expose databases.

    Please see the below figure to understand my situation.

    I want to use five columns (IDIPC, IDKINDCOUNTRY, IDKINDDATE, IDKINDPATENT, IDLOCATION and IDTIME) as keys,

    but I don't want to expose those columns. I want to only expose A, B, C, D, E, F, Value, Flags and IDMetadata.

    Is is possible? I tried to exclude those columns, but it doesn't work. Entity Framework says that 'there is invalid column name.'

    Do you have any ideas about that?



    • Edited by byHesed Thursday, November 22, 2012 5:37 PM
    Thursday, November 22, 2012 1:45 PM

Answers

  • Each entity in OData must have a key property (or a set of key properties). The same applies to EF. If you would hide the key properties, there would be now way for OData to uniquely identify the given entity, and the entire protocol is based on the assumption that you can uniquely identify an entity instance.

    So it is possible to hide any non-key column (through EF), but the key properties must be exposed for this purpose.

    Thanks,


    Vitek Karas [MSFT]

    • Marked as answer by byHesed Monday, November 26, 2012 4:41 PM
    Friday, November 23, 2012 11:03 AM
    Moderator

All replies

  • Each entity in OData must have a key property (or a set of key properties). The same applies to EF. If you would hide the key properties, there would be now way for OData to uniquely identify the given entity, and the entire protocol is based on the assumption that you can uniquely identify an entity instance.

    So it is possible to hide any non-key column (through EF), but the key properties must be exposed for this purpose.

    Thanks,


    Vitek Karas [MSFT]

    • Marked as answer by byHesed Monday, November 26, 2012 4:41 PM
    Friday, November 23, 2012 11:03 AM
    Moderator
  • Thank you, Vitek Karas. Your answer is logically right.

    Here is one more question. If I use Reflection or Custom Service provider, then can I even hide key properties?

    Monday, November 26, 2012 4:50 PM
  • Hi,

    The answer is still no - OData itself needs every entity to have a unique key property (or properties). With reflection/custom provider you could come up with some other key property, but it would still have to be unique in the set, so very likely it would have to be some combination of the existing primary key in the DB.

    Thanks,


    Vitek Karas [MSFT]

    Monday, November 26, 2012 4:55 PM
    Moderator