本文整理汇总了C#中ODataModelBuilder.EntitySet方法的典型用法代码示例。如果您正苦于以下问题:C# ODataModelBuilder.EntitySet方法的具体用法?C# ODataModelBuilder.EntitySet怎么用?C# ODataModelBuilder.EntitySet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataModelBuilder
的用法示例。
在下文中一共展示了ODataModelBuilder.EntitySet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: CanBuildBoundProcedureCacheForIEdmModel
public void CanBuildBoundProcedureCacheForIEdmModel()
{
// Arrange
ODataModelBuilder builder = new ODataModelBuilder();
EntityTypeConfiguration<Customer> customer = builder.EntitySet<Customer>("Customers").EntityType;
customer.HasKey(c => c.ID);
customer.Property(c => c.Name);
customer.ComplexProperty(c => c.Address);
EntityTypeConfiguration<Movie> movie = builder.EntitySet<Movie>("Movies").EntityType;
movie.HasKey(m => m.ID);
movie.HasKey(m => m.Name);
EntityTypeConfiguration<Blockbuster> blockBuster = builder.Entity<Blockbuster>().DerivesFrom<Movie>();
EntityTypeConfiguration movieConfiguration = builder.StructuralTypes.OfType<EntityTypeConfiguration>().Single(t => t.Name == "Movie");
// build actions that are bindable to a single entity
customer.Action("InCache1_CustomerAction");
customer.Action("InCache2_CustomerAction");
movie.Action("InCache3_MovieAction");
ActionConfiguration incache4_MovieAction = builder.Action("InCache4_MovieAction");
incache4_MovieAction.SetBindingParameter("bindingParameter", movieConfiguration, true);
blockBuster.Action("InCache5_BlockbusterAction");
// build actions that are either: bindable to a collection of entities, have no parameter, have only complex parameter
customer.Collection.Action("NotInCache1_CustomersAction");
movie.Collection.Action("NotInCache2_MoviesAction");
ActionConfiguration notInCache3_NoParameters = builder.Action("NotInCache3_NoParameters");
ActionConfiguration notInCache4_AddressParameter = builder.Action("NotInCache4_AddressParameter");
notInCache4_AddressParameter.Parameter<Address>("address");
IEdmModel model = builder.GetEdmModel();
IEdmEntityType customerType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Customer");
IEdmEntityType movieType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Movie");
IEdmEntityType blockBusterType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Blockbuster");
// Act
BindableProcedureFinder annotation = new BindableProcedureFinder(model);
IEdmAction[] movieActions = annotation.FindProcedures(movieType)
.OfType<IEdmAction>()
.ToArray();
IEdmAction[] customerActions = annotation.FindProcedures(customerType)
.OfType<IEdmAction>()
.ToArray();
IEdmAction[] blockBusterActions = annotation.FindProcedures(blockBusterType)
.OfType<IEdmAction>()
.ToArray();
// Assert
Assert.Equal(2, customerActions.Length);
Assert.NotNull(customerActions.SingleOrDefault(a => a.Name == "InCache1_CustomerAction"));
Assert.NotNull(customerActions.SingleOrDefault(a => a.Name == "InCache2_CustomerAction"));
Assert.Equal(2, movieActions.Length);
Assert.NotNull(movieActions.SingleOrDefault(a => a.Name == "InCache3_MovieAction"));
Assert.NotNull(movieActions.SingleOrDefault(a => a.Name == "InCache4_MovieAction"));
Assert.Equal(3, blockBusterActions.Length);
Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache3_MovieAction"));
Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache4_MovieAction"));
Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache5_BlockbusterAction"));
}
示例3: GetTypedExplicitModel
public static IEdmModel GetTypedExplicitModel()
{
ODataModelBuilder builder = new ODataModelBuilder();
var accountType = builder.EntityType<Account>();
accountType.HasKey(c => c.Id);
accountType.Property(c => c.Name);
accountType.HasDynamicProperties(c => c.DynamicProperties);
accountType.ComplexProperty<AccountInfo>(c => c.AccountInfo);
accountType.ComplexProperty<Address>(a => a.Address);
accountType.ComplexProperty<Tags>(a => a.Tags);
var premiumAccountType = builder.EntityType<PremiumAccount>();
premiumAccountType.Property(p => p.Since);
premiumAccountType.DerivesFrom<Account>();
var accountInfoType = builder.ComplexType<AccountInfo>();
accountInfoType.Property(i => i.NickName);
accountInfoType.HasDynamicProperties(i => i.DynamicProperties);
var addressType = builder.ComplexType<Address>();
addressType.Property(a => a.City);
addressType.Property(a => a.Street);
addressType.HasDynamicProperties(a => a.DynamicProperties);
var globalAddressType = builder.ComplexType<GlobalAddress>();
globalAddressType.Property(a => a.CountryCode);
globalAddressType.DerivesFrom<Address>();
var tagsType = builder.ComplexType<Tags>();
tagsType.HasDynamicProperties(t => t.DynamicProperties);
var gender = builder.EnumType<Gender>();
gender.Member(Gender.Female);
gender.Member(Gender.Male);
var employeeType = builder.EntityType<Employee>();
employeeType.HasKey(e => e.Id);
employeeType.HasOptional(e => e.Account);
builder.EntitySet<Employee>("Employees");
var managerType = builder.EntityType<Manager>();
managerType.Property(m => m.Heads);
managerType.HasDynamicProperties(m => m.DynamicProperties);
managerType.DerivesFrom<Employee>();
AddBoundActionsAndFunctions(accountType);
AddUnboundActionsAndFunctions(builder);
EntitySetConfiguration<Account> accounts = builder.EntitySet<Account>("Accounts");
builder.Namespace = typeof(Account).Namespace;
return builder.GetEdmModel();
}
示例4: 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();
}
示例5: GetEdmModel
public static IEdmModel GetEdmModel()
{
if (_model == null)
{
ODataModelBuilder model = new ODataModelBuilder();
var people = model.EntitySet<FormatterPerson>("People");
people.HasIdLink(context => context.UrlHelper.Link(ODataRouteNames.GetById, new { Id = (context.EntityInstance as FormatterPerson).PerId }));
people.HasEditLink(context => new Uri(context.UrlHelper.Link(ODataRouteNames.GetById, new { Id = (context.EntityInstance as FormatterPerson).PerId })));
people.HasReadLink(context => new Uri(context.UrlHelper.Link(ODataRouteNames.GetById, new { Id = (context.EntityInstance as FormatterPerson).PerId })));
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;
}
示例6: 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);
}
示例7: 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));
}
示例8: 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;
}
示例9: 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();
}
示例10: GetModel
private static IEdmModel GetModel()
{
ODataModelBuilder builder = new ODataModelBuilder();
var customers = builder.EntitySet<PropertyCustomer>("PropertyCustomers");
customers.EntityType.HasKey(x => x.Id);
customers.HasIdLink(c => "http://localhost:12345", true);
customers.EntityType.Property(p => p.Name);
return builder.GetEdmModel();
}
示例11: UnboundFunctionPathSegmentTest
public UnboundFunctionPathSegmentTest()
{
ODataModelBuilder builder = new ODataModelBuilder();
builder.EntityType<MyCustomer>().HasKey(c => c.Id).Property(c => c.Name);
builder.EntitySet<MyCustomer>("Customers");
FunctionConfiguration function = builder.Function("TopCustomer");
function.ReturnsFromEntitySet<MyCustomer>("Customers");
builder.Function("MyFunction").Returns<string>();
_model = builder.GetEdmModel();
_container = _model.EntityContainers().Single();
}
示例12: CreateModelWithEntitySet
public void CreateModelWithEntitySet()
{
var builder = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet();
builder.EntitySet<Customer>("Customers");
var model = builder.GetServiceModel();
var container = model.SchemaElements.OfType<IEdmEntityContainer>().SingleOrDefault();
Assert.NotNull(container);
var customers = container.EntitySets().SingleOrDefault(e => e.Name == "Customers");
Assert.NotNull(customers);
Assert.Equal("Customer", customers.ElementType.Name);
}
示例13: UnboundActionPathSegmentTest
public UnboundActionPathSegmentTest()
{
ODataModelBuilder builder = new ODataModelBuilder();
builder.EntityType<MyCustomer>().HasKey(c => c.Id).Property(c => c.Name);
builder.EntitySet<MyCustomer>("Customers");
ActionConfiguration action = builder.Action("CreateCustomer");
action.ReturnsFromEntitySet<MyCustomer>("Customers");
builder.Action("MyAction").Returns<string>();
builder.Action("ActionWithoutReturn");
_model = builder.GetEdmModel();
_container = _model.EntityContainer;
}
示例14: GetExplicitEdmModel
private static IEdmModel GetExplicitEdmModel()
{
var builder = new ODataModelBuilder();
// enum type "Color"
var color = builder.EnumType<Color>();
color.Member(Color.Red);
color.Member(Color.Green);
color.Member(Color.Blue);
color.Member(Color.Yellow);
color.Member(Color.Pink);
color.Member(Color.Purple);
// complex type "Address"
var address = builder.ComplexType<Address>();
address.Property(a => a.City);
address.Property(a => a.Street);
// entity type "Customer"
var customer = builder.EntityType<Customer>().HasKey(c => c.CustomerId);
customer.Property(c => c.Name);
customer.Property(c => c.Token);
// customer.Property(c => c.Email).IsNotNavigable(); // you can call Fluent API
customer.Property(c => c.Email);
customer.CollectionProperty(c => c.Addresses);
customer.CollectionProperty(c => c.FavoriateColors);
customer.HasMany(c => c.Orders);
// entity type "Order"
var order = builder.EntityType<Order>().HasKey(o => o.OrderId);
order.Property(o => o.Price);
// entity sets
builder.EntitySet<Customer>("Customers").HasManyBinding(c => c.Orders, "Orders");
builder.EntitySet<Order>("Orders");
return builder.GetEdmModel();
}
示例15: GetEdmModel
public static IEdmModel GetEdmModel()
{
if (_model == null)
{
ODataModelBuilder model = new ODataModelBuilder();
var color = model.EnumType<Color>();
color.Member(Color.Red);
color.Member(Color.Green);
color.Member(Color.Blue);
var people = model.EntitySet<FormatterPerson>("People");
people.HasFeedSelfLink(context => new Uri(context.Url.CreateODataLink(new EntitySetPathSegment(
context.EntitySet))));
people.HasIdLink(context =>
{
return context.Url.CreateODataLink(
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.EnumProperty(p => p.FavoriteColor);
person.ComplexProperty<FormatterOrder>(p => p.Order);
var order = model.ComplexType<FormatterOrder>();
order.Property(o => o.OrderAmount);
order.Property(o => o.OrderName);
// Add a top level function
var getPersons = model.Function("GetPerson");
getPersons.Parameter<Int32>("PerId");
getPersons.ReturnsFromEntitySet<FormatterPerson>("People");
// Add a top level function which is not included in service document
var getVipPerson = model.Function("GetVipPerson");
getVipPerson.ReturnsFromEntitySet<FormatterPerson>("People");
getVipPerson.IncludeInServiceDocument = false;
_model = model.GetEdmModel();
}
return _model;
}