/// <summary>
 /// Query object of a single item.
 /// </summary>
 /// <param name="context">Context associated with this query.</param>
 /// <param name="path">A string that resolves to a URI.</param>
 /// <param name="isComposable">Whether this query is composable.</param>
 public DataServiceQuerySingle(DataServiceContext context, string path, bool isComposable)
 {
     this.Context      = context;
     this.Query        = context.CreateSingletonQuery <TElement>(path);
     this.IsComposable = isComposable;
     this.isFunction   = true;
 }
Exemple #2
0
        public void TestCreateSingletonQuery()
        {
            DataServiceContext context = new DataServiceContext(new Uri("http://base.org/"));
            var query = context.CreateSingletonQuery <Customer>("Vip");

            Assert.IsTrue(query.Expression is SingletonResourceExpression);
            Assert.AreEqual(typeof(Customer), query.ElementType);
        }
Exemple #3
0
        static async Task Main(string[] args)
        {
            var ctx = new DataServiceContext(new Uri("http://localhost:5000/odata"));

            Console.WriteLine("Click when ready to go...");
            Console.ReadLine();

            var blogs = await ctx
                        .CreateQuery <Blog>("Blogs")
                        .IncludeCount()
                        .ExecuteAsync();

            var blogQuery = ctx
                            .CreateSingletonQuery <Blog>("Blogs")
                            .AddQueryOption("id", 1)
                            //.Where(x => x.BlogId == 1)
                            as DataServiceQuery <Blog>;

            var blog = (await blogQuery.ExecuteAsync()).SingleOrDefault();
        }