本文整理汇总了C#中ODataModelBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ODataModelBuilder类的具体用法?C# ODataModelBuilder怎么用?C# ODataModelBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataModelBuilder类属于命名空间,在下文中一共展示了ODataModelBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Apply_SingleForeignKeyOnForeignKeyProperty_Works
public void Apply_SingleForeignKeyOnForeignKeyProperty_Works()
{
// Arrange
Type dependentType = typeof(SingleDependentEntity2);
ODataModelBuilder builder = new ODataModelBuilder();
builder.Entity<PrincipalEntity>().HasKey(p => p.PrincipalIntId);
EntityTypeConfiguration dependentEntity = builder.AddEntity(dependentType);
PropertyInfo expectPropertyInfo = dependentType.GetProperty("PrincipalId");
PrimitivePropertyConfiguration primitiveProperty = dependentEntity.AddProperty(expectPropertyInfo);
PropertyInfo propertyInfo = dependentType.GetProperty("Principal");
NavigationPropertyConfiguration navigation = dependentEntity.AddNavigationProperty(propertyInfo,
EdmMultiplicity.ZeroOrOne);
navigation.AddedExplicitly = false;
// Act
new ForeignKeyAttributeConvention().Apply(primitiveProperty, dependentEntity);
// Assert
PropertyInfo actualPropertyInfo = Assert.Single(navigation.DependentProperties);
Assert.Same(expectPropertyInfo, actualPropertyInfo);
Assert.Equal("PrincipalIntId", Assert.Single(navigation.PrincipalProperties).Name);
Assert.False(primitiveProperty.OptionalProperty);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:28,代码来源:ForeignKeyAttributeConventionTest.cs
示例2: GetEdmModel
private static IEdmModel GetEdmModel()
{
ODataModelBuilder builder = new ODataModelBuilder();
// Configure LimitedEntity
EntitySetConfiguration<LimitedEntity> limitedEntities = builder.EntitySet<LimitedEntity>("LimitedEntities");
limitedEntities.EntityType.HasKey(p => p.Id);
limitedEntities.EntityType.ComplexProperty(c => c.ComplexProperty);
limitedEntities.EntityType.CollectionProperty(c => c.ComplexCollectionProperty).IsNotCountable();
limitedEntities.EntityType.HasMany(l => l.EntityCollectionProperty).IsNotCountable();
limitedEntities.EntityType.CollectionProperty(cp => cp.Integers).IsNotCountable();
// Configure LimitedRelatedEntity
EntitySetConfiguration<LimitedRelatedEntity> limitedRelatedEntities =
builder.EntitySet<LimitedRelatedEntity>("LimitedRelatedEntities");
limitedRelatedEntities.EntityType.HasKey(p => p.Id);
limitedRelatedEntities.EntityType.CollectionProperty(p => p.ComplexCollectionProperty).IsNotCountable();
// Configure Complextype
ComplexTypeConfiguration<LimitedComplex> complexType = builder.ComplexType<LimitedComplex>();
complexType.CollectionProperty(p => p.Strings).IsNotCountable();
complexType.Property(p => p.Value);
complexType.CollectionProperty(p => p.SimpleEnums).IsNotCountable();
// Configure EnumType
EnumTypeConfiguration<SimpleEnum> enumType = builder.EnumType<SimpleEnum>();
enumType.Member(SimpleEnum.First);
enumType.Member(SimpleEnum.Second);
enumType.Member(SimpleEnum.Third);
enumType.Member(SimpleEnum.Fourth);
return builder.GetEdmModel();
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:33,代码来源:CountQueryValidatorTest.cs
示例3: ConstructorEmptyRawValueThrows
public void ConstructorEmptyRawValueThrows()
{
var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
Assert.Throws<ArgumentException>(() =>
new OrderByQueryOption(string.Empty, new ODataQueryContext(model, typeof(Customer))));
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:7,代码来源:OrderByQueryOptionTest.cs
示例4: Apply
public void Apply(ProcedureConfiguration configuration, ODataModelBuilder model)
{
FunctionConfiguration function = configuration as FunctionConfiguration;
if (function == null || !function.IsBindable)
{
return;
}
// You only need to create links for bindable functions that bind to a single entity.
if (function.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Entity && function.GetFunctionLink() == null)
{
string bindingParamterType = function.BindingParameter.TypeConfiguration.FullName;
function.HasFunctionLink(entityContext =>
entityContext.GenerateFunctionLink(bindingParamterType, function.FullyQualifiedName, function.Parameters.Select(p => p.Name)),
followsConventions: true);
}
else if (function.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Collection && function.GetFeedFunctionLink() == null)
{
if (((CollectionTypeConfiguration)function.BindingParameter.TypeConfiguration).ElementType.Kind ==
EdmTypeKind.Entity)
{
string bindingParamterType = function.BindingParameter.TypeConfiguration.FullName;
function.HasFeedFunctionLink(
feedContext =>
feedContext.GenerateFunctionLink(bindingParamterType, function.FullyQualifiedName, function.Parameters.Select(p => p.Name)),
followsConventions: true);
}
}
}
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:31,代码来源:FunctionLinkGenerationConvention.cs
示例5: NavigationSourceConfiguration
protected NavigationSourceConfiguration(ODataModelBuilder modelBuilder, EntityTypeConfiguration entityType, string name)
{
if (modelBuilder == null)
{
throw Error.ArgumentNull("modelBuilder");
}
if (entityType == null)
{
throw Error.ArgumentNull("entityType");
}
if (String.IsNullOrEmpty(name))
{
throw Error.ArgumentNullOrEmpty("name");
}
_modelBuilder = modelBuilder;
Name = name;
EntityType = entityType;
ClrType = entityType.ClrType;
_url = Name;
_editLinkBuilder = null;
_readLinkBuilder = null;
_navigationPropertyLinkBuilders = new Dictionary<NavigationPropertyConfiguration, NavigationLinkBuilder>();
_navigationPropertyBindings = new Dictionary<NavigationPropertyConfiguration, NavigationPropertyBindingConfiguration>();
}
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:28,代码来源:NavigationSourceConfiguration.cs
示例6: BuildEdmModel
public static IEdmModel BuildEdmModel(ODataModelBuilder builder)
{
if (builder == null)
{
throw Error.ArgumentNull("builder");
}
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer(builder.Namespace, builder.ContainerName);
// add types and sets, building an index on the way.
Dictionary<Type, IEdmStructuredType> edmTypeMap = model.AddTypes(builder.StructuralTypes);
Dictionary<string, EdmEntitySet> edmEntitySetMap = model.AddEntitySets(builder, container, edmTypeMap);
// add procedures
model.AddProcedures(builder.Procedures, container, edmTypeMap, edmEntitySetMap);
// finish up
model.AddElement(container);
// build the map from IEdmEntityType to IEdmFunctionImport
model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model));
return model;
}
开发者ID:jlamfers,项目名称:aspnetwebstack,代码行数:25,代码来源:EdmModelHelperMethods.cs
示例7: GetEdmModel
public static IEdmModel GetEdmModel()
{
if (_model == null)
{
ODataModelBuilder model = new ODataModelBuilder();
var people = model.EntitySet<FormatterPerson>("People");
people.HasFeedSelfLink(context => new Uri(context.Url.ODataLink(new EntitySetPathSegment(
context.EntitySet))));
people.HasIdLink(context =>
{
return context.Url.ODataLink(
new EntitySetPathSegment(context.EntitySet),
new KeyValuePathSegment(context.GetPropertyValue("PerId").ToString()));
},
followsConventions: false);
var person = people.EntityType;
person.HasKey(p => p.PerId);
person.Property(p => p.Age);
person.Property(p => p.MyGuid);
person.Property(p => p.Name);
person.ComplexProperty<FormatterOrder>(p => p.Order);
var order = model.ComplexType<FormatterOrder>();
order.Property(o => o.OrderAmount);
order.Property(o => o.OrderName);
_model = model.GetEdmModel();
}
return _model;
}
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:33,代码来源:ODataTestUtil.cs
示例8: CanUseRelativeLinks
public void CanUseRelativeLinks()
{
var builder = new ODataModelBuilder()
.Add_Customer_EntityType()
.Add_Order_EntityType()
.Add_CustomerOrders_Relationship()
.Add_Customers_EntitySet()
.Add_Orders_EntitySet()
.Add_CustomerOrders_Binding();
var customersSet = builder.EntitySet<Customer>("Customers");
customersSet.HasEditLink(o => new Uri(string.Format("Customers({0})", o.EntityInstance.CustomerId), UriKind.Relative));
customersSet.FindBinding("Orders").HasLinkFactory(o => string.Format("Orders/ByCustomerId/{0}", ((Customer)o.EntityInstance).CustomerId));
var model = builder.GetEdmModel();
var container = model.FindDeclaredEntityContainer("Container");
var customerEdmEntitySet = container.FindEntitySet("Customers");
// TODO: Fix later, need to add a reference
//var entityContext = new EntityInstanceContext<Customer>(model, customerEdmEntitySet, (IEdmEntityType)customerEdmEntitySet.ElementType, null, new Customer { CustomerId = 24 });
//Assert.Equal("Customers", customersSet.GetUrl());
///Assert.Equal("Customers(24)", customersSet.GetEditLink(entityContext).ToString());
//Assert.Equal("Orders/ByCustomerId/24", customersSet.FindBinding("Orders").GetLink(entityContext));
}
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:26,代码来源:RoutingTest.cs
示例9: Apply_KeyNameConventions_Works
public void Apply_KeyNameConventions_Works()
{
// Arrange
ODataModelBuilder builder = new ODataModelBuilder();
EntityTypeConfiguration principalEntity = builder.AddEntity(typeof(DiscoveryPrincipalEntity));
PropertyInfo propertyInfo = typeof(DiscoveryPrincipalEntity).GetProperty("DiscoveryPrincipalEntityId");
principalEntity.HasKey(propertyInfo);
EntityTypeConfiguration dependentEntity = builder.AddEntity(typeof(DiscoveryDependentEntity));
PropertyInfo expectPropertyInfo = typeof(DiscoveryDependentEntity).GetProperty("DiscoveryPrincipalEntityId");
dependentEntity.AddProperty(expectPropertyInfo);
PropertyInfo navigationPropertyInfo = typeof(DiscoveryDependentEntity).GetProperty("Principal");
NavigationPropertyConfiguration navigation = dependentEntity.AddNavigationProperty(navigationPropertyInfo,
EdmMultiplicity.One);
navigation.AddedExplicitly = false;
// Act
new ForeignKeyDiscoveryConvention().Apply(navigation, dependentEntity);
// Assert
PropertyInfo actualPropertyInfo = Assert.Single(navigation.DependentProperties);
Assert.Same(expectPropertyInfo, actualPropertyInfo);
PropertyInfo principalProperty = Assert.Single(navigation.PrincipalProperties);
Assert.Equal("DiscoveryPrincipalEntityId", principalProperty.Name);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:28,代码来源:ForeignKeyDiscoveryConventionTest.cs
示例10: Apply
public void Apply(IEntitySetConfiguration configuration, ODataModelBuilder model)
{
if (configuration == null)
{
throw Error.ArgumentNull("configuration");
}
// We only need to configure the EditLink by convention, ReadLink and IdLink both delegate to EditLink
if (configuration.GetEditLink() == null)
{
configuration.HasEditLink(entityContext =>
{
string routeName = SelfRouteName ?? ODataRouteNames.GetById;
string editlink = entityContext.UrlHelper.Link(
routeName,
new
{
controller = configuration.Name,
id = ConventionsHelpers.GetEntityKeyValue(entityContext, configuration.EntityType)
});
if (editlink == null)
{
throw Error.InvalidOperation(SRResources.GetByIdRouteMissingOrIncorrect, routeName);
}
return new Uri(editlink);
});
}
}
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:28,代码来源:SelfLinksGenerationConvention.cs
示例11: GetExplicitModel
public static IEdmModel GetExplicitModel(string singletonName)
{
ODataModelBuilder builder = new ODataModelBuilder();
// Define EntityType of Partner
var partner = builder.EntityType<Partner>();
partner.HasKey(p => p.ID);
partner.Property(p => p.Name);
var partnerCompany = partner.HasRequired(p => p.Company);
// Define Enum Type
var category = builder.EnumType<CompanyCategory>();
category.Member(CompanyCategory.IT);
category.Member(CompanyCategory.Communication);
category.Member(CompanyCategory.Electronics);
category.Member(CompanyCategory.Others);
// Define EntityType of Company
var company = builder.EntityType<Company>();
company.HasKey(p => p.ID);
company.Property(p => p.Name);
company.Property(p => p.Revenue);
company.EnumProperty(p => p.Category);
var companyPartners = company.HasMany(p => p.Partners);
companyPartners.IsNotCountable();
var companyBranches = company.CollectionProperty(p => p.Branches);
// Define Complex Type: Office
var office = builder.ComplexType<Office>();
office.Property(p => p.City);
office.Property(p => p.Address);
// Define Derived Type: SubCompany
var subCompany = builder.EntityType<SubCompany>();
subCompany.DerivesFrom<Company>();
subCompany.Property(p => p.Location);
subCompany.Property(p => p.Description);
subCompany.ComplexProperty(p => p.Office);
builder.Namespace = typeof(Partner).Namespace;
// Define PartnerSet and Company(singleton)
EntitySetConfiguration<Partner> partnersConfiguration = builder.EntitySet<Partner>("Partners");
partnersConfiguration.HasIdLink(c=>c.GenerateSelfLink(false), true);
partnersConfiguration.HasSingletonBinding(c => c.Company, singletonName);
Func<EntityInstanceContext<Partner>, IEdmNavigationProperty, Uri> link = (eic, np) => eic.GenerateNavigationPropertyLink(np, false);
partnersConfiguration.HasNavigationPropertyLink(partnerCompany, link, true);
partnersConfiguration.EntityType.Collection.Action("ResetDataSource");
SingletonConfiguration<Company> companyConfiguration = builder.Singleton<Company>(singletonName);
companyConfiguration.HasIdLink(c => c.GenerateSelfLink(false), true);
companyConfiguration.HasManyBinding(c => c.Partners, "Partners");
Func<EntityInstanceContext<Company>, IEdmNavigationProperty, Uri> linkFactory = (eic, np) => eic.GenerateNavigationPropertyLink(np, false);
companyConfiguration.HasNavigationPropertyLink(companyPartners, linkFactory, true);
companyConfiguration.EntityType.Action("ResetDataSource");
companyConfiguration.EntityType.Function("GetPartnersCount").Returns<int>();
return builder.GetEdmModel();
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:60,代码来源:SingletonEdmModel.cs
示例12: Apply
public void Apply(EntitySetConfiguration configuration, ODataModelBuilder model)
{
if (configuration == null)
{
throw Error.ArgumentNull("configuration");
}
// generate links without cast for declared and inherited navigation properties
foreach (EntityTypeConfiguration entity in configuration.EntityType.ThisAndBaseTypes())
{
foreach (NavigationPropertyConfiguration property in entity.NavigationProperties)
{
if (configuration.GetNavigationPropertyLink(property) == null)
{
configuration.HasNavigationPropertyLink(
property,
(entityContext, navigationProperty) => GenerateNavigationPropertyLink(entityContext, navigationProperty, configuration, includeCast: false));
}
}
}
// generate links with cast for navigation properties in derived types.
foreach (EntityTypeConfiguration entity in model.DerivedTypes(configuration.EntityType))
{
foreach (NavigationPropertyConfiguration property in entity.NavigationProperties)
{
if (configuration.GetNavigationPropertyLink(property) == null)
{
configuration.HasNavigationPropertyLink(
property,
(entityContext, navigationProperty) => GenerateNavigationPropertyLink(entityContext, navigationProperty, configuration, includeCast: true));
}
}
}
}
开发者ID:cubski,项目名称:aspnetwebstack,代码行数:35,代码来源:NavigationLinksGenerationConvention.cs
示例13: EntitySetConfiguration
public EntitySetConfiguration(ODataModelBuilder modelBuilder, EntityTypeConfiguration entityType, string name)
{
if (modelBuilder == null)
{
throw Error.ArgumentNull("modelBuilder");
}
if (entityType == null)
{
throw Error.ArgumentNull("entityType");
}
if (name == null)
{
throw Error.ArgumentNull("name");
}
_modelBuilder = modelBuilder;
Name = name;
EntityType = entityType;
ClrType = entityType.ClrType;
_url = Name;
_editLinkFactory = null;
_readLinkFactory = null;
_navigationPropertyLinkBuilders = new Dictionary<NavigationPropertyConfiguration, Func<EntityInstanceContext, IEdmNavigationProperty, Uri>>();
_entitySetBindings = new Dictionary<NavigationPropertyConfiguration, NavigationPropertyBinding>();
}
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:28,代码来源:EntitySetConfiguration.cs
示例14: Apply_MultiForeignKeysOnNavigationProperty_Works
public void Apply_MultiForeignKeysOnNavigationProperty_Works()
{
// Arrange
Type dependentType = typeof(MultiDependentEntity);
ODataModelBuilder builder = new ODataModelBuilder();
builder.Entity<PrincipalEntity>().HasKey(p => new { p.PrincipalIntId, p.PrincipalStringId });
EntityTypeConfiguration dependentEntity = builder.AddEntity(dependentType);
PropertyInfo expectPropertyInfo1 = dependentType.GetProperty("PrincipalId1");
dependentEntity.AddProperty(expectPropertyInfo1);
PropertyInfo expectPropertyInfo2 = dependentType.GetProperty("PrincipalId2");
dependentEntity.AddProperty(expectPropertyInfo2);
PropertyInfo propertyInfo = typeof(MultiDependentEntity).GetProperty("Principal");
NavigationPropertyConfiguration navigation = dependentEntity.AddNavigationProperty(propertyInfo,
EdmMultiplicity.One);
navigation.AddedExplicitly = false;
// Act
new ForeignKeyAttributeConvention().Apply(navigation, dependentEntity);
// Assert
Assert.Equal(2, navigation.DependentProperties.Count());
Assert.Same(expectPropertyInfo1, navigation.DependentProperties.First());
Assert.Same(expectPropertyInfo2, navigation.DependentProperties.Last());
Assert.Equal(2, navigation.PrincipalProperties.Count());
Assert.Equal("PrincipalIntId", navigation.PrincipalProperties.First().Name);
Assert.Equal("PrincipalStringId", navigation.PrincipalProperties.Last().Name);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:33,代码来源:ForeignKeyAttributeConventionTest.cs
示例15: CanCreateFunctionWithNoArguments
public void CanCreateFunctionWithNoArguments()
{
// Arrange
// Act
ODataModelBuilder builder = new ODataModelBuilder();
builder.Namespace = "MyNamespace";
builder.ContainerName = "MyContainer";
FunctionConfiguration function = builder.Function("Format");
// Assert
Assert.Equal("Format", function.Name);
Assert.Equal(ProcedureKind.Function, function.Kind);
Assert.NotNull(function.Parameters);
Assert.Empty(function.Parameters);
Assert.Null(function.ReturnType);
Assert.False(function.IsSideEffecting);
Assert.False(function.IsComposable);
Assert.False(function.IsBindable);
Assert.False(function.SupportedInFilter);
Assert.False(function.SupportedInOrderBy);
Assert.Equal("MyContainer.Format", function.ContainerQualifiedName);
Assert.Equal("MyContainer.Format", function.FullName);
Assert.Equal("MyNamespace.MyContainer.Format", function.FullyQualifiedName);
Assert.NotNull(builder.Procedures);
Assert.Equal(1, builder.Procedures.Count());
}
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:26,代码来源:FunctionConfigurationTest.cs
示例16: CreateQueryOptions_SetsContextProperties_WithModelAndPath
public void CreateQueryOptions_SetsContextProperties_WithModelAndPath()
{
// Arrange
ApiController controller = new Mock<ApiController>().Object;
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Customers");
controller.Configuration = new HttpConfiguration();
ODataModelBuilder odataModel = new ODataModelBuilder();
string setName = typeof(Customer).Name;
odataModel.EntityType<Customer>().HasKey(c => c.Id);
odataModel.EntitySet<Customer>(setName);
IEdmModel model = odataModel.GetEdmModel();
IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet(setName);
request.ODataProperties().Model = model;
request.ODataProperties().Path = new ODataPath(new EntitySetPathSegment(entitySet));
controller.Request = request;
// Act
ODataQueryOptions<Customer> queryOptions =
EntitySetControllerHelpers.CreateQueryOptions<Customer>(controller);
// Assert
Assert.Same(model, queryOptions.Context.Model);
Assert.Same(entitySet, queryOptions.Context.NavigationSource);
Assert.Same(typeof(Customer), queryOptions.Context.ElementClrType);
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:25,代码来源:EntitySetControllerHelpersTest.cs
示例17: ConstructorNullRawValueThrows
public void ConstructorNullRawValueThrows()
{
var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
Assert.Throws<ArgumentException>(() =>
new SkipQueryOption(null, new ODataQueryContext(model, typeof(Customer), "Customers")));
}
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:7,代码来源:SkipQueryOptionTests.cs
示例18: GetExplicitModel
public static IEdmModel GetExplicitModel()
{
ODataModelBuilder builder = new ODataModelBuilder();
var customerType = builder.EntityType<DCustomer>().HasKey(c => c.Id);
customerType.Property(c => c.DateTime);
customerType.Property(c => c.Offset);
customerType.Property(c => c.Date);
customerType.Property(c => c.TimeOfDay);
customerType.Property(c => c.NullableDateTime);
customerType.Property(c => c.NullableOffset);
customerType.Property(c => c.NullableDate);
customerType.Property(c => c.NullableTimeOfDay);
customerType.CollectionProperty(c => c.DateTimes);
customerType.CollectionProperty(c => c.Offsets);
customerType.CollectionProperty(c => c.Dates);
customerType.CollectionProperty(c => c.TimeOfDays);
customerType.CollectionProperty(c => c.NullableDateTimes);
customerType.CollectionProperty(c => c.NullableOffsets);
customerType.CollectionProperty(c => c.NullableDates);
customerType.CollectionProperty(c => c.NullableTimeOfDays);
var customers = builder.EntitySet<DCustomer>("DCustomers");
customers.HasIdLink(link, true);
customers.HasEditLink(link, true);
BuildFunctions(builder);
BuildActions(builder);
return builder.GetEdmModel();
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:33,代码来源:DateAndTimeOfDayEdmModel.cs
示例19: AddEntitySets
private static Dictionary<string, EdmEntitySet> AddEntitySets(this EdmModel model, ODataModelBuilder builder, EdmEntityContainer container, Dictionary<Type, IEdmStructuredType> edmTypeMap)
{
IEnumerable<EntitySetConfiguration> configurations = builder.EntitySets;
// build the entitysets and their annotations
IEnumerable<Tuple<EdmEntitySet, EntitySetConfiguration>> entitySets = AddEntitySets(configurations, container, edmTypeMap);
var entitySetAndAnnotations = entitySets.Select(e => new
{
EntitySet = e.Item1,
Configuration = e.Item2,
Annotations = new
{
LinkBuilder = new EntitySetLinkBuilderAnnotation(e.Item2),
Url = new EntitySetUrlAnnotation { Url = e.Item2.GetUrl() }
}
}).ToArray();
// index the entitySets by name
Dictionary<string, EdmEntitySet> edmEntitySetMap = entitySetAndAnnotations.ToDictionary(e => e.EntitySet.Name, e => e.EntitySet);
// apply the annotations
foreach (var iter in entitySetAndAnnotations)
{
EdmEntitySet entitySet = iter.EntitySet;
model.SetAnnotationValue<EntitySetUrlAnnotation>(entitySet, iter.Annotations.Url);
model.SetAnnotationValue<IEntitySetLinkBuilder>(entitySet, iter.Annotations.LinkBuilder);
AddNavigationBindings(iter.Configuration, iter.EntitySet, iter.Annotations.LinkBuilder, builder, edmTypeMap, edmEntitySetMap);
}
return edmEntitySetMap;
}
开发者ID:jlamfers,项目名称:aspnetwebstack,代码行数:31,代码来源:EdmModelHelperMethods.cs
示例20: CanCreateActionWithNoArguments
public void CanCreateActionWithNoArguments()
{
// Arrange
// Act
ODataModelBuilder builder = new ODataModelBuilder();
builder.Namespace = "MyNamespace";
builder.ContainerName = "MyContainer";
ActionConfiguration action = builder.Action("Format");
ActionConfiguration actionII = builder.Action("FormatII");
actionII.Namespace = "MyNamespaceII";
// Assert
Assert.Equal("Format", action.Name);
Assert.Equal(ProcedureKind.Action, action.Kind);
Assert.NotNull(action.Parameters);
Assert.Empty(action.Parameters);
Assert.Null(action.ReturnType);
Assert.True(action.IsSideEffecting);
Assert.False(action.IsComposable);
Assert.False(action.IsBindable);
Assert.Equal("MyNamespace", action.Namespace);
Assert.Equal("MyNamespace.Format", action.FullyQualifiedName);
Assert.Equal("MyNamespaceII", actionII.Namespace);
Assert.Equal("MyNamespaceII.FormatII", actionII.FullyQualifiedName);
Assert.NotNull(builder.Procedures);
Assert.Equal(2, builder.Procedures.Count());
}
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:27,代码来源:ActionConfigurationTest.cs
注:本文中的ODataModelBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论