本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmEntityType.FindProperty方法的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityType.FindProperty方法的具体用法?C# EdmEntityType.FindProperty怎么用?C# EdmEntityType.FindProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmEntityType
的用法示例。
在下文中一共展示了EdmEntityType.FindProperty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEntityType
private static IEdmEntityType CreateEntityType(
MetadataWorkspace efModel,
EntityType efEntityType,
EdmModel model,
IDictionary<MetadataItem, IEdmElement> elementMap,
out List<EdmStructuralProperty> concurrencyProperties)
{
// TODO GitHubIssue#36 : support complex and entity inheritance
var objectSpaceType = efModel.GetObjectSpaceType(efEntityType) as EntityType;
var entityType = new EdmEntityType(objectSpaceType.NamespaceName, objectSpaceType.Name);
concurrencyProperties = null;
foreach (var efProperty in efEntityType.Properties)
{
var type = GetTypeReference(efProperty, model, elementMap);
if (type != null)
{
string defaultValue = null;
if (efProperty.DefaultValue != null)
{
defaultValue = efProperty.DefaultValue.ToString();
}
var property = entityType.AddStructuralProperty(
efProperty.Name,
type,
defaultValue,
EdmConcurrencyMode.None); // alway None:replaced by OptimisticConcurrency annotation
MetadataProperty storeGeneratedPattern = null;
efProperty.MetadataProperties.TryGetValue(
AnnotationSchema + StoreGeneratedPatternKey,
true,
out storeGeneratedPattern);
if (storeGeneratedPattern != null &&
(string)storeGeneratedPattern.Value == StoreGeneratedPatternValueComputed)
{
SetComputedAnnotation(model, property);
}
if (efProperty.ConcurrencyMode == ConcurrencyMode.Fixed)
{
concurrencyProperties = concurrencyProperties ?? new List<EdmStructuralProperty>();
concurrencyProperties.Add(property);
}
}
}
entityType.AddKeys(efEntityType.KeyProperties
.Select(p => entityType.FindProperty(p.Name))
.Cast<IEdmStructuralProperty>());
return entityType;
}
示例2: CreateTripPinServiceModel
//.........这里部分代码省略.........
var me = new EdmSingleton(defaultContainer, "Me", personType);
defaultContainer.AddElement(me);
personSet.AddNavigationTarget(friendsnNavigation, personSet);
me.AddNavigationTarget(friendsnNavigation, personSet);
personSet.AddNavigationTarget(flightAirlineNavigation, airlineSet);
me.AddNavigationTarget(flightAirlineNavigation, airlineSet);
personSet.AddNavigationTarget(flightFromAirportNavigation, airportSet);
me.AddNavigationTarget(flightFromAirportNavigation, airportSet);
personSet.AddNavigationTarget(flightToAirportNavigation, airportSet);
me.AddNavigationTarget(flightToAirportNavigation, airportSet);
personSet.AddNavigationTarget(personPhotoNavigation, photoSet);
me.AddNavigationTarget(personPhotoNavigation, photoSet);
personSet.AddNavigationTarget(tripPhotosNavigation, photoSet);
me.AddNavigationTarget(tripPhotosNavigation, photoSet);
var getFavoriteAirlineFunction = new EdmFunction(ns, "GetFavoriteAirline",
new EdmEntityTypeReference(airlineType, false), true,
new EdmPathExpression("person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline"), true);
getFavoriteAirlineFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
model.AddElement(getFavoriteAirlineFunction);
var getInvolvedPeopleFunction = new EdmFunction(ns, "GetInvolvedPeople",
new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(personType, false))), true, null, true);
getInvolvedPeopleFunction.AddParameter("trip", new EdmEntityTypeReference(tripType, false));
model.AddElement(getInvolvedPeopleFunction);
var getFriendsTripsFunction = new EdmFunction(ns, "GetFriendsTrips",
new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(tripType, false))),
true, new EdmPathExpression("person/Friends/Trips"), true);
getFriendsTripsFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
getFriendsTripsFunction.AddParameter("userName", EdmCoreModel.Instance.GetString(false));
model.AddElement(getFriendsTripsFunction);
var getNearestAirport = new EdmFunction(ns, "GetNearestAirport",
new EdmEntityTypeReference(airportType, false),
false, null, true);
getNearestAirport.AddParameter("lat", EdmCoreModel.Instance.GetDouble(false));
getNearestAirport.AddParameter("lon", EdmCoreModel.Instance.GetDouble(false));
model.AddElement(getNearestAirport);
var getNearestAirportFunctionImport = (IEdmFunctionImport)defaultContainer.AddFunctionImport("GetNearestAirport", getNearestAirport, new EdmEntitySetReferenceExpression(airportSet), true);
var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
model.AddElement(resetDataSourceAction);
defaultContainer.AddActionImport(resetDataSourceAction);
var shareTripAction = new EdmAction(ns, "ShareTrip", null, true, null);
shareTripAction.AddParameter("person", new EdmEntityTypeReference(personType, false));
shareTripAction.AddParameter("userName", EdmCoreModel.Instance.GetString(false));
shareTripAction.AddParameter("tripId", EdmCoreModel.Instance.GetInt32(false));
model.AddElement(shareTripAction);
model.SetDescriptionAnnotation(defaultContainer, "TripPin service is a sample service for OData V4.");
model.SetOptimisticConcurrencyAnnotation(personSet, personType.StructuralProperties().Where(p => p.Name == "Concurrency"));
// TODO: currently singleton does not support ETag feature
// model.SetOptimisticConcurrencyAnnotation(me, personType.StructuralProperties().Where(p => p.Name == "Concurrency"));
model.SetResourcePathCoreAnnotation(personSet, "People");
model.SetResourcePathCoreAnnotation(me, "Me");
model.SetResourcePathCoreAnnotation(airlineSet, "Airlines");
model.SetResourcePathCoreAnnotation(airportSet, "Airports");
model.SetResourcePathCoreAnnotation(photoSet, "Photos");
model.SetResourcePathCoreAnnotation(getNearestAirportFunctionImport, "Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport");
model.SetDereferenceableIDsCoreAnnotation(defaultContainer, true);
model.SetConventionalIDsCoreAnnotation(defaultContainer, true);
model.SetPermissionsCoreAnnotation(personType.FindProperty("UserName"), CorePermission.Read);
model.SetPermissionsCoreAnnotation(airlineType.FindProperty("AirlineCode"), CorePermission.Read);
model.SetPermissionsCoreAnnotation(airportType.FindProperty("IcaoCode"), CorePermission.Read);
model.SetPermissionsCoreAnnotation(planItemType.FindProperty("PlanItemId"), CorePermission.Read);
model.SetPermissionsCoreAnnotation(tripType.FindProperty("TripId"), CorePermission.Read);
model.SetPermissionsCoreAnnotation(photoType.FindProperty("Id"), CorePermission.Read);
model.SetImmutableCoreAnnotation(airportType.FindProperty("IataCode"), true);
model.SetComputedCoreAnnotation(personType.FindProperty("Concurrency"), true);
model.SetAcceptableMediaTypesCoreAnnotation(photoType, new[] { "image/jpeg" });
model.SetConformanceLevelCapabilitiesAnnotation(defaultContainer, CapabilitiesConformanceLevelType.Advanced);
model.SetSupportedFormatsCapabilitiesAnnotation(defaultContainer, new[] { "application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true" });
model.SetAsynchronousRequestsSupportedCapabilitiesAnnotation(defaultContainer, true);
model.SetBatchContinueOnErrorSupportedCapabilitiesAnnotation(defaultContainer, false);
model.SetNavigationRestrictionsCapabilitiesAnnotation(personSet, CapabilitiesNavigationType.None, new[] { new Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>(friendsnNavigation, CapabilitiesNavigationType.Recursive) });
model.SetFilterFunctionsCapabilitiesAnnotation(defaultContainer, new[] { "contains", "endswith", "startswith", "length", "indexof", "substring", "tolower", "toupper", "trim", "concat", "year", "month", "day", "hour", "minute", "second", "round", "floor", "ceiling", "cast", "isof" });
model.SetSearchRestrictionsCapabilitiesAnnotation(personSet, true, CapabilitiesSearchExpressions.None);
model.SetSearchRestrictionsCapabilitiesAnnotation(airlineSet, true, CapabilitiesSearchExpressions.None);
model.SetSearchRestrictionsCapabilitiesAnnotation(airportSet, true, CapabilitiesSearchExpressions.None);
model.SetSearchRestrictionsCapabilitiesAnnotation(photoSet, true, CapabilitiesSearchExpressions.None);
model.SetInsertRestrictionsCapabilitiesAnnotation(personSet, true, new[] { personTripNavigation, friendsnNavigation });
model.SetInsertRestrictionsCapabilitiesAnnotation(airlineSet, true, null);
model.SetInsertRestrictionsCapabilitiesAnnotation(airportSet, false, null);
model.SetInsertRestrictionsCapabilitiesAnnotation(photoSet, true, null);
// TODO: model.SetUpdateRestrictionsCapabilitiesAnnotation();
model.SetDeleteRestrictionsCapabilitiesAnnotation(airportSet, false, null);
model.SetISOCurrencyMeasuresAnnotation(tripType.FindProperty("Budget"), "USD");
model.SetScaleMeasuresAnnotation(tripType.FindProperty("Budget"), 2);
return model;
}
示例3: CreateEntityType
private static IEdmEntityType CreateEntityType(
IModel efModel, IEntityType efEntityType,
EdmModel model, out List<EdmStructuralProperty> concurrencyProperties)
{
// TODO GitHubIssue#36 : support complex and entity inheritance
var entityType = new EdmEntityType(
efEntityType.ClrType.Namespace, efEntityType.ClrType.Name);
concurrencyProperties = null;
foreach (var efProperty in efEntityType.GetProperties())
{
var type = ModelProducer.GetPrimitiveTypeReference(efProperty);
if (type != null)
{
string defaultValue = null;
if (efProperty.SqlServer().DefaultValue != null)
{
defaultValue = efProperty.SqlServer().DefaultValue.ToString();
}
var property = entityType.AddStructuralProperty(
efProperty.Name, type, defaultValue,
EdmConcurrencyMode.None); // alway None:replaced by OptimisticConcurrency annotation
// TODO GitHubIssue#57: Complete EF7 to EDM model mapping
if (efProperty.StoreGeneratedAlways)
{
SetComputedAnnotation(model, property);
}
if (efProperty.IsConcurrencyToken)
{
concurrencyProperties = concurrencyProperties ?? new List<EdmStructuralProperty>();
concurrencyProperties.Add(property);
}
}
}
var key = efEntityType.GetPrimaryKey();
if (key != null)
{
entityType.AddKeys(key.Properties
.Select(p => entityType.FindProperty(p.Name))
.Cast<IEdmStructuralProperty>());
}
return entityType;
}
示例4: CheckNewModelHasNoVersion
public void CheckNewModelHasNoVersion()
{
EdmModel model = new EdmModel();
EdmEntityType t1 = new EdmEntityType("Bunk", "T1");
EdmStructuralProperty p1 = t1.AddStructuralProperty("P1", EdmCoreModel.Instance.GetBoolean(false));
EdmStructuralProperty p2 = t1.AddStructuralProperty("P2", EdmCoreModel.Instance.GetDecimal(1, 1, false));
EdmStructuralProperty p3 = t1.AddStructuralProperty("P3", EdmCoreModel.Instance.GetTemporal(EdmPrimitiveTypeKind.Duration, 1, false));
EdmStructuralProperty p4 = t1.AddStructuralProperty("P4", EdmCoreModel.Instance.GetBinary(false, 4, false));
EdmStructuralProperty p5 = t1.AddStructuralProperty("P5", EdmCoreModel.Instance.GetBinary(false));
IEdmStructuralProperty q1 = (IEdmStructuralProperty)t1.FindProperty("P1");
IEdmStructuralProperty q2 = (IEdmStructuralProperty)t1.FindProperty("P2");
IEdmStructuralProperty q3 = (IEdmStructuralProperty)t1.FindProperty("P3");
IEdmStructuralProperty q4 = (IEdmStructuralProperty)t1.FindProperty("P4");
IEdmStructuralProperty q5 = (IEdmStructuralProperty)t1.FindProperty("P5");
model.AddElement(t1);
Assert.IsNull(model.GetEdmVersion(), "Version is null");
StringWriter sw = new StringWriter();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = System.Text.Encoding.UTF8;
XmlWriter xw = XmlWriter.Create(sw, settings);
IEnumerable<EdmError> errors;
model.TryWriteCsdl(xw, out errors);
xw.Flush();
xw.Close();
string outputText = sw.ToString();
IEdmModel iEdmModel;
bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(outputText)) }, out iEdmModel, out errors);
Assert.IsTrue(parsed, "Model Parsed");
Assert.IsTrue(errors.Count() == 0, "No errors");
Assert.AreEqual(EdmConstants.EdmVersionLatest, iEdmModel.GetEdmVersion(), "Version check");
}