locked
QueryInterceptor and Entity Framework code first RRS feed

  • Question

  • Hello,

    I want to do a query in my QueryInterceptor method. This is a stupid sample that works well : 
    public class WcfDataService : DataService<MyDbContext>
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetPageSize("*", 100);
            config.SetEntitySetAccessRule("Interventions", EntitySetRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }        
    
        [QueryInterceptor("Interventions")]
        public Expression<Func<Intervention, bool>> OnQueryInterventions()
        {
            var inter = ((IObjectContextAdapter)CurrentDataSource).ObjectContext.CreateObjectSet<Intervention>();
            return (i => inter.Any(j => j.Object.StartsWith("changement") && i.Id == j.Id));
        }
    }
    But, if I replace the line :
    var inter = ((IObjectContextAdapter)CurrentDataSource).ObjectContext.CreateObjectSet<Intervention>();
    by
    var inter = CurrentDataSource.Set<Intervention>();
    it doesn't work. Why does it work with ObjectSet and not with DbSet ?

    Cordially,
    Kakone.

    • Edited by _Kakone_ Tuesday, March 27, 2012 2:09 PM
    Tuesday, March 27, 2012 2:07 PM

Answers

All replies