none
Ad-hoc column list in WCF Service function return type RRS feed

  • Question

  • Hi,

    I have one Employee table in database. It contains 50 columns (different kind of datatypes) and 50,000 rows. Now I need to create one WCF service which will return List of Employees. I can use Entity Framework or my custom code and return List<Employee>

    But I have multiple clients (around 10). Some want only 3 columns information (like ID, Name, Age). Some want all 50 columns information, some want only 10 columns, some want 22 columns information and so on....

    Which architecture I should use in this case. If I will return all columns information then in case when client is just requesting for 3 columns information then un-necessary system will return extra 47 column information. Even we don't want to return other information to send as it may be a security issue.

    Should I create 10 different functions for each my client? I think this will be a bad solution as in future if new client will come and other set of columns then again I need to modify my service.

    Is there any way in Entity Framework so that we can return only specific column information, or return NULL which column are not request (so there is no performance or security hit)? Or any better way instead of Entity Framework.

    Please suggest.

    Thanks

    Paresh


    Paresh

    Friday, January 10, 2014 5:07 AM

Answers

  • Hi,

    You can do this with QueryView. This implies editing your model directly in XML as there is no designer support for this, but you will get an independant entity with less fields than the original one.

    Advantages:

    • You can then query data base for this truncated entity directly (you will get only fields you need from the data base - no need to get whole entity from DB and trancate it in code)  
    • It is good in scenarios where you want to send this truncated entity to the client       with WCF to minimize traffic (e.g. when building big lists on client       that basically need only name and ID and no other entity specific       information).

    Disadvantages:

    • This QueryView-based entity is read only. To make it writeable you will have to add r/w functionality yourself

    http://stackoverflow.com/questions/8266546/how-to-display-only-specific-columns-of-a-table-in-entity-framework .

    Wednesday, January 15, 2014 10:33 AM