本文整理汇总了C#中DataServiceContext.AddLink方法的典型用法代码示例。如果您正苦于以下问题:C# DataServiceContext.AddLink方法的具体用法?C# DataServiceContext.AddLink怎么用?C# DataServiceContext.AddLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataServiceContext
的用法示例。
在下文中一共展示了DataServiceContext.AddLink方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InnerSubmit
private void InnerSubmit(DataServiceContext dataContext)
{
if (!string.IsNullOrWhiteSpace(this.TemplateId))
{
dataContext.AddObject(JobBaseCollection.JobSet, this);
foreach (IAsset asset in this.InputMediaAssets)
{
AssetData target = asset as AssetData;
if (target == null)
{
throw new ArgumentException(StringTable.ErrorInputTypeNotSupported);
}
dataContext.AttachTo(AssetCollection.AssetSet, asset);
dataContext.AddLink(this, InputMediaAssetsPropertyName, target);
}
}
else
{
X509Certificate2 certToUse = null;
Verify(this);
dataContext.AddObject(JobBaseCollection.JobSet, this);
List<AssetData> inputAssets = new List<AssetData>();
AssetNamingSchemeResolver<AssetData, OutputAsset> assetNamingSchemeResolver = new AssetNamingSchemeResolver<AssetData, OutputAsset>(inputAssets);
foreach (ITask task in ((IJob)this).Tasks)
{
Verify(task);
TaskData taskData = (TaskData)task;
if (task.Options.HasFlag(TaskOptions.ProtectedConfiguration))
{
ProtectTaskConfiguration(taskData, ref certToUse, dataContext);
}
taskData.TaskBody = CreateTaskBody(assetNamingSchemeResolver, task.InputAssets.ToArray(), task.OutputAssets.ToArray());
taskData.InputMediaAssets.AddRange(task.InputAssets.OfType<AssetData>().ToArray());
taskData.OutputMediaAssets.AddRange(
task.OutputAssets
.OfType<OutputAsset>()
.Select(
c =>
{
AssetData assetData = new AssetData { Name = c.Name, Options = (int)c.Options, AlternateId = c.AlternateId };
assetData.InitCloudMediaContext(this._cloudMediaContext);
return assetData;
})
.ToArray());
dataContext.AddRelatedObject(this, TasksPropertyName, taskData);
}
foreach (IAsset asset in inputAssets)
{
dataContext.AttachTo(AssetCollection.AssetSet, asset);
dataContext.AddLink(this, InputMediaAssetsPropertyName, asset);
}
}
}
示例2: SerializeEnity_TwoNavigationLinksInJsonFormat
public void SerializeEnity_TwoNavigationLinksInJsonFormat()
{
var person = new Person
{
ID = 100,
Name = "Bing",
};
var car1 = new Car { ID = 1001 };
var car2 = new Car { ID = 1002 };
DataServiceContext dataServiceContext = new DataServiceContext(new Uri("http://www.odata.org/service.svc"));
dataServiceContext.AttachTo("Persons", person);
dataServiceContext.AttachTo("Cars", car1);
dataServiceContext.AttachTo("Cars", car2);
dataServiceContext.AddLink(person, "Cars", car1);
dataServiceContext.AddLink(person, "Cars", car2);
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;
entityDescriptor.EditLink = new Uri("http://www.foo.com/custom");
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, "Cars", car2, clientModel)};
var odataRequestMessageWrapper = ODataRequestMessageWrapper.CreateRequestMessageWrapper(requestMessageArgs, requestInfo);
serializer.WriteEntry(entityDescriptor, linkDescriptors, odataRequestMessageWrapper);
// read result:
MemoryStream stream = (MemoryStream)(odataRequestMessageWrapper.CachedRequestStream.Stream);
stream.Position = 0;
string payload = (new StreamReader(stream)).ReadToEnd();
payload.Should().Be(
"{\"ID\":100,\"Name\":\"Bing\",\"[email protected]\":[\"http://www.odata.org/service.svc/Cars(1001)\",\"http://www.odata.org/service.svc/Cars(1002)\"]}");
}