当前位置: 首页>>代码示例>>C#>>正文


C# DataServiceContext类代码示例

本文整理汇总了C#中DataServiceContext的典型用法代码示例。如果您正苦于以下问题:C# DataServiceContext类的具体用法?C# DataServiceContext怎么用?C# DataServiceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataServiceContext类属于命名空间,在下文中一共展示了DataServiceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RequestInfo

 /// <summary>
 /// Creates a new instance of RequestInfo class which is used to build the request to send to the server
 /// </summary>
 /// <param name="context">wrapping context instance.</param>
 internal RequestInfo(DataServiceContext context)
 {
     Debug.Assert(context != null, "context != null");
     this.Context = context;
     this.WriteHelper = new ODataMessageWritingHelper(this);
     this.typeResolver = new TypeResolver(context.Model, context.ResolveTypeFromName, context.ResolveNameFromTypeInternal, context.Format.ServiceModel);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:11,代码来源:RequestInfo.cs

示例2: ExecuteAssetDeleteRequest

 private static Uri ExecuteAssetDeleteRequest( AssetDeleteOptionsRequestAdapter adapter)
 {
     Uri uri = null;
     var context = new DataServiceContext(new Uri("http://127.0.0.1/" + Guid.NewGuid().ToString()));
     bool sendingRequestCalled = false;
     context.SendingRequest2 += delegate(object o, SendingRequest2EventArgs args)
     {
         sendingRequestCalled = true;
         uri = args.RequestMessage.Url;
     };
     try
     {
         AssetData asset = new AssetData() {Id = Guid.NewGuid().ToString()};
         context.AttachTo("Assets", asset);
         context.DeleteObject(asset);
         adapter.Adapt(context);
         context.SaveChanges();
     }
     catch (DataServiceRequestException ex)
     {
         Debug.WriteLine(ex.Message);
     }
     Assert.IsTrue(sendingRequestCalled);
     return uri;
 }
开发者ID:JeromeZhao,项目名称:azure-sdk-for-media-services,代码行数:25,代码来源:AssetDeleteOptionsRequestAdapterTests.cs

示例3: Init

        public void Init()
        {
            context = new DataServiceContext(new Uri(rootUrl));

            this.sampleDateTimeOffset = new DateTime(2012, 12, 17, 9, 23, 31, DateTimeKind.Utc);
            this.sampleDate = XmlConvert.ToString(this.sampleDateTimeOffset);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:7,代码来源:LinqIntegrationTests.cs

示例4: Translate

        /// <summary>
        /// Translates resource bound expression tree to a URI.
        /// </summary>
        /// <param name='context'>Data context used to generate type names for types.</param>
        /// <param name="addTrailingParens">flag to indicate whether generated URI should include () if leaf is ResourceSet</param>
        /// <param name="e">The expression to translate</param>
        /// <param name="uri">uri</param>
        /// <param name="version">version for query</param>    
        internal static void Translate(DataServiceContext context, bool addTrailingParens, Expression e, out Uri uri, out Version version)
        {
            var writer = new UriWriter(context);
            writer.Visit(e);
            string fullUri = writer.uriBuilder.ToString();

            if (writer.alias.Any())
            {
                if (fullUri.IndexOf(UriHelper.QUESTIONMARK) > -1)
                {
                    fullUri += UriHelper.AMPERSAND;
                }
                else
                {
                    fullUri += UriHelper.QUESTIONMARK;
                }

                foreach (var kv in writer.alias)
                {
                    fullUri += kv.Key;
                    fullUri += UriHelper.EQUALSSIGN;
                    fullUri += kv.Value;
                    fullUri += UriHelper.AMPERSAND;
                }

                fullUri = fullUri.Substring(0, fullUri.Length - 1);
            }
            

            uri = UriUtil.CreateUri(fullUri, UriKind.Absolute);
            version = writer.uriVersion;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:40,代码来源:UriWriter.cs

示例5: SetupSerializerAndCallWriteEntry

        /// <summary>
        /// Instantiates a new Serializer class and calls WriteEntry method on it.
        /// </summary>
        /// <param name="dataServiceContext"></param>
        /// <returns></returns>
        private static Person SetupSerializerAndCallWriteEntry(DataServiceContext dataServiceContext)
        {
            Person person = new Person();
            Address address = new Address();
            Car car1 = new Car();
            person.Cars.Add(car1);
            person.HomeAddress = address;

            dataServiceContext.AttachTo("Cars", car1);
            dataServiceContext.AttachTo("Addresses", address);

            var requestInfo = new RequestInfo(dataServiceContext);
            var serializer = new Serializer(requestInfo);
            var headers = new HeaderCollection();
            var clientModel = new ClientEdmModel(ODataProtocolVersion.V4);
            var entityDescriptor = new EntityDescriptor(clientModel);
            entityDescriptor.State = EntityStates.Added;
            entityDescriptor.Entity = person;
            var requestMessageArgs = new BuildingRequestEventArgs("POST", new Uri("http://www.foo.com/Northwind"), headers, entityDescriptor, HttpStack.Auto);
            var linkDescriptors = new LinkDescriptor[] { new LinkDescriptor(person, "Cars", car1, clientModel), new LinkDescriptor(person, "HomeAddress", address, clientModel) };
            var odataRequestMessageWrapper = ODataRequestMessageWrapper.CreateRequestMessageWrapper(requestMessageArgs, requestInfo);

            serializer.WriteEntry(entityDescriptor, linkDescriptors, odataRequestMessageWrapper);
            return person;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:30,代码来源:ODataWriterWrapperUnitTests.cs

示例6: EndToEndShortIntegrationWriteEntryEventTest

        public void EndToEndShortIntegrationWriteEntryEventTest()
        {
            List<KeyValuePair<string, object>> eventArgsCalled = new List<KeyValuePair<string, object>>();
            var dataServiceContext = new DataServiceContext(new Uri("http://www.odata.org/Service.svc"));
            dataServiceContext.Configurations.RequestPipeline.OnEntityReferenceLink((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnEntityReferenceLink", args)));
            dataServiceContext.Configurations.RequestPipeline.OnEntryEnding((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnEntryEnded", args)));
            dataServiceContext.Configurations.RequestPipeline.OnEntryStarting((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnEntryStarted", args)));
            dataServiceContext.Configurations.RequestPipeline.OnNavigationLinkEnding((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnNavigationLinkEnded", args)));
            dataServiceContext.Configurations.RequestPipeline.OnNavigationLinkStarting((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnNavigationLinkStarted", args)));

            Person person = SetupSerializerAndCallWriteEntry(dataServiceContext);

            eventArgsCalled.Should().HaveCount(8);
            eventArgsCalled[0].Key.Should().Be("OnEntryStarted");
            eventArgsCalled[0].Value.Should().BeOfType<WritingEntryArgs>();
            eventArgsCalled[0].Value.As<WritingEntryArgs>().Entity.Should().BeSameAs(person);
            eventArgsCalled[1].Key.Should().Be("OnNavigationLinkStarted");
            eventArgsCalled[1].Value.Should().BeOfType<WritingNavigationLinkArgs>();
            eventArgsCalled[2].Key.Should().Be("OnEntityReferenceLink");
            eventArgsCalled[2].Value.Should().BeOfType<WritingEntityReferenceLinkArgs>();
            eventArgsCalled[3].Key.Should().Be("OnNavigationLinkEnded");
            eventArgsCalled[3].Value.Should().BeOfType<WritingNavigationLinkArgs>();
            eventArgsCalled[4].Key.Should().Be("OnNavigationLinkStarted");
            eventArgsCalled[4].Value.Should().BeOfType<WritingNavigationLinkArgs>();
            eventArgsCalled[5].Key.Should().Be("OnEntityReferenceLink");
            eventArgsCalled[5].Value.Should().BeOfType<WritingEntityReferenceLinkArgs>();
            eventArgsCalled[6].Key.Should().Be("OnNavigationLinkEnded");
            eventArgsCalled[6].Value.Should().BeOfType<WritingNavigationLinkArgs>();
            eventArgsCalled[7].Key.Should().Be("OnEntryEnded");
            eventArgsCalled[7].Value.Should().BeOfType<WritingEntryArgs>();
            eventArgsCalled[7].Value.As<WritingEntryArgs>().Entity.Should().BeSameAs(person);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:32,代码来源:ODataWriterWrapperUnitTests.cs

示例7: NamedStreams_LoadPropertyTest

        //[TestMethod, Variation("One should not be able to get named streams via load property api")]
        public void NamedStreams_LoadPropertyTest()
        {
            // populate the context
            DataServiceContext context = new DataServiceContext(request.ServiceRoot, ODataProtocolVersion.V4);
            EntityWithNamedStreams1 entity = context.CreateQuery<EntityWithNamedStreams1>("MySet1").Take(1).Single();

            try
            {
                context.LoadProperty(entity, "Stream1");
            }
            catch (DataServiceClientException ex)
            {
                Assert.IsTrue(ex.Message.Contains(DataServicesResourceUtil.GetString("DataService_VersionTooLow", "1.0", "3", "0")), String.Format("The error message was not as expected: {0}", ex.Message));
            }

            try
            {
                context.BeginLoadProperty(
                    entity,
                    "Stream1",
                    (result) => { context.EndLoadProperty(result); },
                    null);
            }
            catch (DataServiceClientException ex)
            {
                Assert.IsTrue(ex.Message.Contains(DataServicesResourceUtil.GetString("DataService_VersionTooLow", "1.0", "3", "0")), String.Format("The error message was not as expected: {0}", ex.Message));
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:29,代码来源:NamedStream_ProjectionTests.cs

示例8: Analyze

        /// <summary>
        /// Analyzes a lambda expression to check whether it can be satisfied with
        /// $select and client-side materialization.
        /// </summary>
        /// <param name="le">Lambda expression.</param>
        /// <param name="re">Resource expression in scope.</param>
        /// <param name="matchMembers">Whether member accesses are matched as top-level projections.</param>
        /// <param name="context">Context of expression to analyze.</param>
        /// <returns>true if the lambda is a client-side projection; false otherwise.</returns>
        internal static bool Analyze(LambdaExpression le, ResourceExpression re, bool matchMembers, DataServiceContext context)
        {
            Debug.Assert(le != null, "le != null");

            if (le.Body.NodeType == ExpressionType.Constant)
            {
                if (ClientTypeUtil.TypeOrElementTypeIsEntity(le.Body.Type))
                {
                    throw new NotSupportedException(Strings.ALinq_CannotCreateConstantEntity);
                }

                re.Projection = new ProjectionQueryOptionExpression(le.Body.Type, le, new List<string>());
                return true;
            }

            if (le.Body.NodeType == ExpressionType.MemberInit || le.Body.NodeType == ExpressionType.New)
            {
                AnalyzeResourceExpression(le, re, context);
                return true;
            }

            if (matchMembers)
            {
                // Members can be projected standalone or type-casted.
                Expression withoutConverts = SkipConverts(le.Body);
                if (withoutConverts.NodeType == ExpressionType.MemberAccess)
                {
                    AnalyzeResourceExpression(le, re, context);
                    return true;
                }
            }

            return false;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:43,代码来源:ProjectionAnalyzer.cs

示例9: RegisterDataService

        public static Uri RegisterDataService(DataServiceContext ctx)
        {
            if (_behavior == null)
                Behavior = Activator.CreateInstance(OAuthConfiguration.Configuration.ClientSettings.WcfDSBehaviorType) as IOAuthBehavior;

            return Behavior.RegisterDataService(ctx);
        }
开发者ID:koder05,项目名称:fogel-ba,代码行数:7,代码来源:OAuthProvider.cs

示例10: ClientSerializeGeographyTest_BindingAddChangeShouldBeDetected

 public void ClientSerializeGeographyTest_BindingAddChangeShouldBeDetected()
 {
     DataServiceContext ctx = new DataServiceContext(new Uri("http://localhost"));
     DataServiceCollection<SpatialEntityType> dsc = new DataServiceCollection<SpatialEntityType>(ctx, null, TrackingMode.AutoChangeTracking, "Entities", null, null);
     dsc.Add(testEntity);
     ClientSerializeGeographyTest_Validate(ctx);
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:7,代码来源:SpatialTypeIntegrationTests.cs

示例11: UriWriter

 private UriWriter(DataServiceContext context)
 {
     Debug.Assert(context != null, "context != null");
     this.context = context;
     this.uriBuilder = new StringBuilder();
     this.uriVersion = Util.DataServiceVersion1;
 }
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:UriWriter.cs

示例12: UnregisterEventHandler

        /// <summary>
        /// Unregisters this verifier from the context's event
        /// </summary>
        /// <param name="context">The context to stop verifing events on</param>
        /// <param name="inErrorState">A value indicating that we are recovering from an error</param>
        public void UnregisterEventHandler(DataServiceContext context, bool inErrorState)
        {
            ExceptionUtilities.CheckArgumentNotNull(context, "context");
#if !WINDOWS_PHONE
            this.HttpTracker.UnregisterHandler(context, this.HandleRequestResponsePair, !inErrorState);
#endif
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:12,代码来源:DataServiceResponsePreferenceVerifier.cs

示例13: SqlSampleDataPageViewModel

 public SqlSampleDataPageViewModel(Dispatcher dispatcher, DataServiceContext odataServiceContext)
 {
     this.dispatcher = dispatcher;
     this.Context = odataServiceContext;
     this.Items = new DataServiceCollection<SqlSampleData>(odataServiceContext);
     this.Items.LoadCompleted += this.OnLoadCompleted;
 }
开发者ID:junleqian,项目名称:Mobile-Restaurant,代码行数:7,代码来源:SqlSampleDataPageViewModel.cs

示例14: BatchSaveResult

 /// <summary>
 /// constructor for BatchSaveResult
 /// </summary>
 /// <param name="context">context</param>
 /// <param name="method">method</param>
 /// <param name="queries">queries</param>
 /// <param name="options">options</param>
 /// <param name="callback">user callback</param>
 /// <param name="state">user state object</param>
 internal BatchSaveResult(DataServiceContext context, string method, DataServiceRequest[] queries, SaveChangesOptions options, AsyncCallback callback, object state)
     : base(context, method, queries, options, callback, state)
 {
     Debug.Assert(Util.IsBatch(options), "the options must have batch  flag set");
     this.Queries = queries;
     this.streamCopyBuffer = new byte[StreamCopyBufferSize];
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:16,代码来源:BatchSaveResult.cs

示例15: WebGrid

        //
        // GET: /OData/
        public ActionResult WebGrid(int page = 1, int rowsPerPage = 10, string sort = "ProductID", string sortDir = "ASC")
        {
            DataServiceContext   nwd = new DataServiceContext(new Uri("http://services.odata.org/Northwind/Northwind.svc/"));

               var Products2 =
              (QueryOperationResponse<Product>)nwd.Execute<Product>(
              new Uri("http://services.odata.org/Northwind/Northwind.svc/Products()?$expand=Category,Supplier&$select=ProductID,ProductName,Category/CategoryName,Supplier/CompanyName,Supplier/Country"));

            var t = from p in Products2
                    select new JointProductModel
                    {
                        ProductID = p.ProductID,
                        ProductName = p.ProductName,
                        CategoryName = p.Category.CategoryName,
                        CompanyName = p.Supplier.CompanyName,
                        Country = p.Supplier.Country
                    };

              // ViewBag.count = t.Count();

            ViewBag.page = page;
            ViewBag.rowsPerPage = rowsPerPage;
            ViewBag.sort = sort;
            ViewBag.sortDir = sortDir;
            var r2 = t.AsQueryable().OrderBy(sort + " " + sortDir).Skip((page - 1) * rowsPerPage).Take(rowsPerPage);
            return View(r2.ToList());
        }
开发者ID:sOm2y,项目名称:CS335s2_A2,代码行数:29,代码来源:ODataController.cs


注:本文中的DataServiceContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。