本文整理汇总了C#中IEdmModel.GetEdmVersion方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmModel.GetEdmVersion方法的具体用法?C# IEdmModel.GetEdmVersion怎么用?C# IEdmModel.GetEdmVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmModel
的用法示例。
在下文中一共展示了IEdmModel.GetEdmVersion方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryWriteEdmx
/// <summary>
/// Outputs an EDMX artifact to the provided XmlWriter.
/// </summary>
/// <param name="model">Model to be written.</param>
/// <param name="writer">XmlWriter the generated EDMX will be written to.</param>
/// <param name="target">Target implementation of the EDMX being generated.</param>
/// <param name="errors">Errors that prevented successful serialization, or no errors if serialization was successfull. </param>
/// <returns>A value indicating whether serialization was successful.</returns>
public static bool TryWriteEdmx(IEdmModel model, XmlWriter writer, EdmxTarget target, out IEnumerable<EdmError> errors)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(writer, "writer");
errors = model.GetSerializationErrors();
if (errors.FirstOrDefault() != null)
{
return false;
}
Version edmxVersion = model.GetEdmxVersion();
if (edmxVersion != null)
{
if (!CsdlConstants.SupportedEdmxVersions.ContainsKey(edmxVersion))
{
errors = new EdmError[] { new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmxVersion, Edm.Strings.Serializer_UnknownEdmxVersion) };
return false;
}
}
else if (!CsdlConstants.EdmToEdmxVersions.TryGetValue(model.GetEdmVersion() ?? EdmConstants.EdmVersionLatest, out edmxVersion))
{
errors = new EdmError[] { new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmVersion, Edm.Strings.Serializer_UnknownEdmVersion) };
return false;
}
IEnumerable<EdmSchema> schemas = new EdmModelSchemaSeparationSerializationVisitor(model).GetSchemas();
EdmxWriter edmxWriter = new EdmxWriter(model, schemas, writer, edmxVersion, target);
edmxWriter.WriteEdmx();
errors = Enumerable.Empty<EdmError>();
return true;
}
示例2: ShouldValidateComplexPropertyNullValue
internal static bool ShouldValidateComplexPropertyNullValue(IEdmModel model)
{
Version edmVersion = model.GetEdmVersion();
Version dataServiceVersion = model.GetDataServiceVersion();
if (((edmVersion != null) && (dataServiceVersion != null)) && (edmVersion < ODataVersion.V3.ToDataServiceVersion()))
{
return false;
}
return true;
}
示例3: WriteSchemas
internal static void WriteSchemas(IEdmModel model, IEnumerable<EdmSchema> schemas, Func<string, XmlWriter> writerProvider)
{
EdmModelCsdlSerializationVisitor visitor;
Version edmVersion = model.GetEdmVersion() ?? EdmConstants.EdmVersionLatest;
foreach (EdmSchema schema in schemas)
{
XmlWriter writer = writerProvider(schema.Namespace);
if (writer != null)
{
visitor = new EdmModelCsdlSerializationVisitor(model, writer, edmVersion);
visitor.VisitEdmSchema(schema, model.GetNamespacePrefixMappings());
}
}
}
示例4: TryWriteEdmx
public static bool TryWriteEdmx(IEdmModel model, XmlWriter writer, EdmxTarget target, out IEnumerable<EdmError> errors)
{
EdmUtil.CheckArgumentNull<IEdmModel>(model, "model");
EdmUtil.CheckArgumentNull<XmlWriter>(writer, "writer");
errors = model.GetSerializationErrors();
if (errors.FirstOrDefault<EdmError>() == null)
{
Version edmxVersion = model.GetEdmxVersion();
if (edmxVersion == null)
{
Dictionary<Version, Version> edmToEdmxVersions = CsdlConstants.EdmToEdmxVersions;
Version edmVersion = model.GetEdmVersion();
Version edmVersionLatest = edmVersion;
if (edmVersion == null)
{
edmVersionLatest = EdmConstants.EdmVersionLatest;
}
if (!edmToEdmxVersions.TryGetValue(edmVersionLatest, out edmxVersion))
{
EdmError[] edmError = new EdmError[1];
edmError[0] = new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmVersion, Strings.Serializer_UnknownEdmVersion);
errors = edmError;
return false;
}
}
else
{
if (!CsdlConstants.SupportedEdmxVersions.ContainsKey(edmxVersion))
{
EdmError[] edmErrorArray = new EdmError[1];
edmErrorArray[0] = new EdmError(new CsdlLocation(0, 0), EdmErrorCode.UnknownEdmxVersion, Strings.Serializer_UnknownEdmxVersion);
errors = edmErrorArray;
return false;
}
}
IEnumerable<EdmSchema> schemas = (new EdmModelSchemaSeparationSerializationVisitor(model)).GetSchemas();
EdmxWriter edmxWriter = new EdmxWriter(model, schemas, writer, edmxVersion, target);
edmxWriter.WriteEdmx();
errors = Enumerable.Empty<EdmError>();
return true;
}
else
{
return false;
}
}
示例5: WriteSchemas
internal static void WriteSchemas(IEdmModel model, IEnumerable<EdmSchema> schemas, Func<string, XmlWriter> writerProvider)
{
Version edmVersion = model.GetEdmVersion();
Version edmVersionLatest = edmVersion;
if (edmVersion == null)
{
edmVersionLatest = EdmConstants.EdmVersionLatest;
}
Version version = edmVersionLatest;
foreach (EdmSchema schema in schemas)
{
XmlWriter @namespace = writerProvider(schema.Namespace);
if (@namespace == null)
{
continue;
}
EdmModelCsdlSerializationVisitor edmModelCsdlSerializationVisitor = new EdmModelCsdlSerializationVisitor(model, @namespace, version);
edmModelCsdlSerializationVisitor.VisitEdmSchema(schema, model.GetNamespacePrefixMappings());
}
}
示例6: ShouldValidateComplexPropertyNullValue
/// <summary>
/// Null validation of complex properties will be skipped if edm version is less than v3 and data service version exists.
/// In such cases, the provider decides what should be done if a null value is stored on a non-nullable complex property.
/// </summary>
/// <param name="model">The model containing the complex property.</param>
/// <returns>True if complex property should be validated for null values.</returns>
internal static bool ShouldValidateComplexPropertyNullValue(IEdmModel model)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(model != null, "For null validation model is required.");
Debug.Assert(model.IsUserModel(), "For complex properties, the model should be user model.");
Version edmVersion = model.GetEdmVersion();
Version dataServiceVersion = model.GetDataServiceVersion();
if (edmVersion != null && dataServiceVersion != null && edmVersion < ODataVersion.V3.ToDataServiceVersion())
{
return false;
}
return true;
}
示例7: CompareMetadata
public static void CompareMetadata(IEdmModel expectedItems, IEdmModel actualItems, bool isReflectionBasedProvider, string defaultEntityContainerName, ServiceContainer serviceContainer)
{
//
// Verify the metadata version is correct, the number of entity containers is 1, the entity
// container names match, and the number of entity types are the same
//
AstoriaTestLog.AreEqual(1.1, actualItems.GetEdmVersion(), "The metadata version was not correct");
AstoriaTestLog.AreEqual(serviceContainer.Workspace.ContextTypeName, actualItems.EntityContainer.Name, "Entity Container names do not match");
if (!isReflectionBasedProvider)
{
AstoriaTestLog.AreEqual(expectedItems.SchemaElements.OfType<IEdmEntityType>().Count(), actualItems.SchemaElements.OfType<IEdmEntityType>().Count(), "Entity Type Counts do not match");
}
foreach (IEdmOperationImport metadataExposedFunction in actualItems.EntityContainer.OperationImports())
{
AstoriaTestLog.TraceInfo("--> " + metadataExposedFunction.Name);
}
//
// For each entity type exposed through the metadata endpoint, verify the following
// 1. Verify it has an equivalent definition in the resource container
// 2. Verify the entity type name is correct
// 3. Verify that no navigation property is exposed in the entity type
// 4. Verify that the property count in the entity type
//
IEnumerable<ComplexType> rtTypeCollection = serviceContainer.AllTypes.Where(a => a.GetType().Name.Equals("ResourceType"));
AstoriaTestLog.TraceInfo(rtTypeCollection.Count().ToString());
foreach (IEdmEntityType metadataExposedEntityType in actualItems.SchemaElements.OfType<IEdmEntityType>())
{
ResourceType resourceContainerEntityType = serviceContainer.AllTypes.Where(b => b.GetType().Name.Equals("ResourceType") & (b.FullName.Equals(metadataExposedEntityType.FullName()))).FirstOrDefault() as ResourceType;
if (resourceContainerEntityType == null)
continue;
AstoriaTestLog.IsNotNull(resourceContainerEntityType, "Did not find entity type in resource container");
AstoriaTestLog.AreEqual(resourceContainerEntityType.FullName, metadataExposedEntityType.FullName(), "Entity Type name mismatch");
//
// Verify the name, type, and nullable attribute values
//
ResourceContainer rc = serviceContainer.ResourceContainers.Where(a => a.BaseType.Name.Equals(metadataExposedEntityType.Name)).FirstOrDefault();
if (rc == null)
continue;
int navCount = rc.BaseType.Properties.Cast<NodeProperty>().Cast<ResourceProperty>().Where(a => a.IsNavigation).Count();
AstoriaTestLog.TraceInfo(rc.Name);
AstoriaTestLog.TraceInfo(navCount.ToString());
AstoriaTestLog.AreEqual(resourceContainerEntityType.Properties.Count - navCount, metadataExposedEntityType.Properties().Count(), "Edm Property count mismatch");
foreach (IEdmProperty metadataExposedProperty in metadataExposedEntityType.Properties())
{
string errorStringEntityTypeProperty = metadataExposedEntityType.FullName() + " : " + metadataExposedProperty.Name;
NodeProperty resourceContainerProperty = resourceContainerEntityType.Properties.Where(a => a.Name.Equals(metadataExposedProperty.Name)).FirstOrDefault();
AstoriaTestLog.IsNotNull(resourceContainerProperty, "Did not find property -->" + errorStringEntityTypeProperty + "<-- in resource container");
if (resourceContainerProperty == null)
continue;
if (metadataExposedProperty.Type.IsBinary())
{
if (AstoriaTestProperties.DataLayerProviderKinds.Contains(DataLayerProviderKind.LinqToSql))
AstoriaTestLog.AreEqual("System.Data.Linq.Binary", resourceContainerProperty.Type.ClrType.FullName, errorStringEntityTypeProperty + " type is incorrect");
else
AstoriaTestLog.AreEqual("System.Byte[]", resourceContainerProperty.Type.ClrType.FullName, errorStringEntityTypeProperty + " type is incorrect");
}
else
{
AstoriaTestLog.AreEqual(metadataExposedProperty.Type.FullName(), resourceContainerProperty.Type.FullName, errorStringEntityTypeProperty + " type is incorrect");
}
}
}
}