How does (configuration of) filtering work with WCF/EF/SQL Server views?

20 Views Asked by At

I am currently trying to understand how filtering of result sets is working in a legacy project written in C# (.NET 4.7.2) using WCF and EF5. The tool makes heavy use of SQL Server views (instead of using C#+EF for handling Business logic). So if a user refreshs a data grid, the endpoint associated with the DB View is called. WCF handles calling the view and provides the data for the client.

It is possible that the client application receives only relevant parts of the data (e.g. the current stock level of a specific article) if a filter parameter is added to the endpoint URI. However, the server-side app does not handle this behaviour explicitely (as I would expect based on my humble experience with django/drf apps).

To give you an impression on the sparse configuration:

 [JSONPSupportBehavior]
    public class DataService : DataService<DbContextEntities>, IServiceProvider
    {
        public DataService()
        {

            string uri = HttpContext.Current.Request.Url.OriginalString;
            StringBuilder replaceUri = new StringBuilder();

             // do stuff 
            OperationContext.Current.IncomingMessageProperties["MicrosoftDataServicesRequestUri"] = new Uri(replaceUri.ToString());
        }

        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }

    }

Here is exemplary the data model context:

 public partial class DbContextEntities : DbContext
    {
        public DbContextEntities()
            : base("name=DbContextEntities")
        {
        }
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
    
        public DbSet<vw_stock> vw_stock { get; set; } //this is the SQL server view
        
  1. How does WCF handle dataset filtering?
  2. How do I configure this behaviour?
  3. (Is it possible to enable server-side pagination with WCF out of the box)?

Until now, WCF feels like black magic for me. I consulted the documentation (https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/filtering), but did not find helpful examples for how this filtering stuff works. Additionally, there is a lot of stuff in the docs that don't exist in my code base (e.g. I don't have an explicit data contract in my application, config is really sparse).

So guidance is highly appreciated! ;)

Kind regards, Martina

1

There are 1 best solutions below

0
Martina Thiele On

..figured that WCF is only the plattform that enables communication between server and client. The service that provides filtering is: ODATA.

Here you can find basic query options: learn.microsoft.com/en-us/odata/client/query-options

ODATA provides also query options $top and $skip that can be useful for pagination.

Best, Martina