本文整理汇总了C#中ODataModelBuilder.EntityType方法的典型用法代码示例。如果您正苦于以下问题:C# ODataModelBuilder.EntityType方法的具体用法?C# ODataModelBuilder.EntityType怎么用?C# ODataModelBuilder.EntityType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataModelBuilder
的用法示例。
在下文中一共展示了ODataModelBuilder.EntityType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: GetEdmModel
public static IEdmModel GetEdmModel()
{
var builder = new ODataModelBuilder();
var employee = builder.EntityType<Employee>();
employee.HasKey(e => e.EmployeeID);
employee.HasMany(e => e.Orders);
var order = builder.EntityType<Order>();
order.HasKey(c => c.OrderID);
order.HasMany(c => c.OrderDetails);
return builder.GetEdmModel();
}
示例4: BuildFunctions
private static void BuildFunctions(ODataModelBuilder builder)
{
FunctionConfiguration GetWeapons =
builder.EntityType<Hero>()
.Collection.Function("GetWeapons")
.ReturnsCollectionFromEntitySet<Weapon>("Weapons");
GetWeapons.IsComposable = true;
FunctionConfiguration GetNames =
builder.EntityType<Hero>()
.Collection.Function("GetNames")
.ReturnsCollection<string>();
GetNames.IsComposable = true;
}
示例5: 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();
}
示例6: NonbindingParameterConfigurationSupportsParameterTypeAs
public void NonbindingParameterConfigurationSupportsParameterTypeAs(Type type, bool isNullable)
{
// Arrange
ODataModelBuilder builder = new ODataModelBuilder();
builder.EntityType<Customer>();
builder.ComplexType<Address>();
builder.EnumType<Color>();
// Act
Type underlyingType = TypeHelper.GetUnderlyingTypeOrSelf(type);
IEdmTypeConfiguration edmTypeConfiguration = builder.GetTypeConfigurationOrNull(type);
if (underlyingType.IsEnum)
{
edmTypeConfiguration = builder.GetTypeConfigurationOrNull(underlyingType);
if (edmTypeConfiguration != null && isNullable)
{
edmTypeConfiguration = ((EnumTypeConfiguration)edmTypeConfiguration).GetNullableEnumTypeConfiguration();
}
}
NonbindingParameterConfiguration parameter = new NonbindingParameterConfiguration("name",
edmTypeConfiguration);
// Assert
Assert.Equal(isNullable, parameter.OptionalParameter);
}
示例7: CanCreateEntityWithCollectionProperties
public void CanCreateEntityWithCollectionProperties()
{
var builder = new ODataModelBuilder();
var customer = builder.EntityType<Customer>();
customer.HasKey(c => c.CustomerId);
customer.CollectionProperty(c => c.Aliases);
customer.CollectionProperty(c => c.Addresses);
var aliasesProperty = customer.Properties.OfType<CollectionPropertyConfiguration>().SingleOrDefault(p => p.Name == "Aliases");
var addressesProperty = customer.Properties.OfType<CollectionPropertyConfiguration>().SingleOrDefault(p => p.Name == "Addresses");
Assert.Equal(3, customer.Properties.Count());
Assert.Equal(2, customer.Properties.OfType<CollectionPropertyConfiguration>().Count());
Assert.NotNull(aliasesProperty);
Assert.Equal(typeof(string), aliasesProperty.ElementType);
Assert.NotNull(addressesProperty);
Assert.Equal(typeof(Address), addressesProperty.ElementType);
Assert.Equal(2, builder.StructuralTypes.Count());
var addressType = builder.StructuralTypes.Skip(1).FirstOrDefault();
Assert.NotNull(addressType);
Assert.Equal(EdmTypeKind.Complex, addressType.Kind);
Assert.Equal(typeof(Address).FullName, addressType.FullName);
var model = builder.GetServiceModel();
var edmCustomerType = model.FindType(typeof(Customer).FullName) as IEdmEntityType;
var edmAddressType = model.FindType(typeof(Address).FullName) as IEdmComplexType;
}
示例8: 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);
}
示例9: 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.EntityType<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);
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"));
}
示例10: BuildFunctions
private static void BuildFunctions(ODataModelBuilder builder)
{
FunctionConfiguration function =
builder.EntityType<File>()
.Collection.Function("GetFilesModifiedAt")
.ReturnsCollectionViaEntitySetPath<File>("bindingParameter");
function.Parameter<DateTime>("modifiedDate");
}
示例11: CreateComplexTypeProperty
public void CreateComplexTypeProperty()
{
var builder = new ODataModelBuilder().Add_Customer_EntityType().Add_Address_ComplexType();
builder.EntityType<Customer>().ComplexProperty(c => c.Address);
var model = builder.GetServiceModel();
var customerType = model.SchemaElements.OfType<IEdmEntityType>().Single();
var addressProperty = customerType.FindProperty("Address");
Assert.NotNull(addressProperty);
}
示例12: 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();
}
示例13: GetExplicitModel
public static IEdmModel GetExplicitModel()
{
ODataModelBuilder builder = new ODataModelBuilder();
var accountType = builder.EntityType<Account>();
accountType.HasKey(a => a.AccountID);
accountType.Property(a => a.Name);
var payoutPI = accountType.ContainsOptional(a => a.PayoutPI);
var payinPIs = accountType.HasMany(a => a.PayinPIs)
.Contained();
var premiumAccountType = builder.EntityType<PremiumAccount>()
.DerivesFrom<Account>();
var giftCard = premiumAccountType.ContainsRequired(pa => pa.GiftCard);
var giftCardType = builder.EntityType<GiftCard>();
giftCardType.HasKey(g => g.GiftCardID);
giftCardType.Property(g => g.GiftCardNO);
giftCardType.Property(g => g.Amount);
var paymentInstrumentType = builder.EntityType<PaymentInstrument>();
paymentInstrumentType.HasKey(pi => pi.PaymentInstrumentID);
paymentInstrumentType.Property(pi => pi.FriendlyName);
var statement = paymentInstrumentType.ContainsOptional(pi => pi.Statement);
var statementType = builder.EntityType<Statement>();
statementType.HasKey(s => s.StatementID);
statementType.Property(s => s.TransactionDescription);
statementType.Property(s => s.Amount);
var accounts = builder.EntitySet<Account>("Accounts");
accounts.HasIdLink(c => c.GenerateSelfLink(false), true);
accounts.HasEditLink(c => c.GenerateSelfLink(true), true);
builder.Singleton<Account>("AnonymousAccount");
AddBoundActionsAndFunctions(builder);
builder.Namespace = typeof(Account).Namespace;
return builder.GetEdmModel();
}
示例14: 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;
}
示例15: 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();
}