本文整理汇总了C#中Microsoft.Test.Taupo.Contracts.EntityModel.EntityModelSchema类的典型用法代码示例。如果您正苦于以下问题:C# EntityModelSchema类的具体用法?C# EntityModelSchema怎么用?C# EntityModelSchema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntityModelSchema类属于Microsoft.Test.Taupo.Contracts.EntityModel命名空间,在下文中一共展示了EntityModelSchema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compare
/// <summary>
/// Compares the two models to each other and throws an exception when there is an erro
/// </summary>
/// <param name="expectedTestEntityModel">EntityModelSchema to compare y to</param>
/// <param name="actualEntityModelSchema">EntityModelSchema to compare x to</param>
/// <returns>List of errors</returns>
public ICollection<string> Compare(EntityModelSchema expectedTestEntityModel, EntityModelSchema actualEntityModelSchema)
{
this.errors = new List<string>();
foreach (ComplexType complexType in expectedTestEntityModel.ComplexTypes)
{
List<ComplexType> complexTypes = actualEntityModelSchema.ComplexTypes.Where(ct => ct.FullName == complexType.FullName).ToList();
if (!this.WriteErrorIfFalse(complexTypes.Count == 1, "Cannot find complexType '{0}'", complexType.Name))
{
ComplexType ycomplexType = complexTypes.Single();
this.CompareComplexType(complexType, ycomplexType);
}
}
foreach (EntityType expectedEntityType in expectedTestEntityModel.EntityTypes)
{
List<EntityType> entityTypes = actualEntityModelSchema.EntityTypes.Where(et => et.FullName == expectedEntityType.FullName).ToList();
if (!this.WriteErrorIfFalse(entityTypes.Count == 1, "Cannot find entityType '{0}'", expectedEntityType.Name))
{
EntityType actualEntityType = entityTypes.Single();
this.CompareEntityTypes(expectedEntityType, actualEntityType);
}
}
foreach (EntityContainer expectedEntityContainer in expectedTestEntityModel.EntityContainers)
{
List<EntityContainer> entityContainers = actualEntityModelSchema.EntityContainers.Where(ec => ec.Name == expectedEntityContainer.Name).ToList();
if (!this.WriteErrorIfFalse(entityContainers.Count == 1, "Cannot find entityContainer '{0}'", expectedEntityContainer.Name))
{
EntityContainer actualEntityContainer = entityContainers.Single();
this.CompareEntityContainer(expectedEntityContainer, actualEntityContainer);
}
}
return this.errors;
}
示例2: Fixup
/// <summary>
/// Remove concurrency tokens defined on complex types and properties
/// </summary>
/// <param name="model">The model to fix up</param>
public void Fixup(EntityModelSchema model)
{
foreach (var ct in model.ComplexTypes)
{
foreach (var property in ct.Properties)
{
// ToList is to avoid modifying the collection during enumeration
foreach (var annotation in property.Annotations.OfType<ConcurrencyTokenAnnotation>().ToList())
{
property.Annotations.Remove(annotation);
}
}
}
foreach (var et in model.EntityTypes)
{
foreach (var property in et.AllProperties.Where(p => p.PropertyType is ComplexDataType))
{
// ToList is to avoid modifying the collection during enumeration
foreach (var annotation in property.Annotations.OfType<ConcurrencyTokenAnnotation>().ToList())
{
property.Annotations.Remove(annotation);
}
}
}
}
示例3: ConvertToEdmModel
/// <summary>
/// Converts a model from Taupo term into Edm term
/// </summary>
/// <param name="taupoModel">The input model in Taupo term</param>
/// <returns>The output model in Edm term</returns>
public IEdmModel ConvertToEdmModel(EntityModelSchema taupoModel)
{
IEnumerable<XElement> csdlElements = this.GenerateCsdlElements(taupoModel);
IEdmModel resultEdmModel = this.GetParserResult(csdlElements);
return resultEdmModel;
}
示例4: Fixup
/// <summary>
/// Remove navigation properties defined on derived types
/// </summary>
/// <param name="model">The model to fix up</param>
public void Fixup(EntityModelSchema model)
{
foreach (var function in model.Functions.ToList().Where(f => f.Annotations.OfType<ServiceOperationAnnotation>().Any(so => so.IsAction)))
{
model.Remove(function);
}
}
示例5: ParseSingleXsdl
/// <summary>
/// Parses a single csdl/ssdl file.
/// </summary>
/// <param name="model">the entity model schema which the csdl/ssdl file parses to</param>
/// <param name="schemaElement">the top level schema element in the csdl/ssdl file</param>
protected virtual void ParseSingleXsdl(EntityModelSchema model, XElement schemaElement)
{
this.AssertXsdlElement(schemaElement, "Schema");
this.SetupNamespaceAndAliases(schemaElement);
foreach (var entityContainerElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityContainer")))
{
model.Add(this.ParseEntityContainer(entityContainerElement));
}
foreach (var entityTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "EntityType")))
{
model.Add(this.ParseEntityType(entityTypeElement));
}
foreach (var associationTypeElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Association")))
{
model.Add(this.ParseAssociation(associationTypeElement));
}
foreach (var functionElement in schemaElement.Elements().Where(el => this.IsXsdlElement(el, "Function")))
{
model.Add(this.ParseFunction(functionElement));
}
}
示例6: Improve
/// <summary>
/// Improve the model if goals not yet met
/// </summary>
/// <param name="model">model to improve</param>
public override void Improve(EntityModelSchema model)
{
while (model.EntityTypes.Count() < this.MinNumberOfEntities)
{
model.Add(new EntityType());
}
}
示例7: Fixup
/// <summary>
/// Add default EntityContainer to the given EntitySchemaModel
/// For each base entity type, add an EntitySet
/// For each association, add an AssociationSet, between two possible EntitySets
/// </summary>
/// <param name="model">the given EntitySchemaModel</param>
public void Fixup(EntityModelSchema model)
{
EntityContainer container = model.EntityContainers.FirstOrDefault();
if (container == null)
{
container = new EntityContainer(this.DefaultContainerName);
model.Add(container);
}
foreach (EntityType entity in model.EntityTypes.Where(e => e.BaseType == null && !container.EntitySets.Any(set => set.EntityType == e)))
{
if (!entity.Annotations.OfType<FixupNoSetAnnotation>().Any())
{
container.Add(new EntitySet(entity.Name, entity));
}
}
foreach (AssociationType association in model.Associations.Where(assoc => !container.AssociationSets.Any(assocSet => assocSet.AssociationType == assoc)))
{
if (!association.Annotations.OfType<FixupNoSetAnnotation>().Any())
{
container.Add(new AssociationSet(association.Name, association)
{
Ends =
{
new AssociationSetEnd(association.Ends[0], container.EntitySets.First(es => association.Ends[0].EntityType.IsKindOf(es.EntityType))),
new AssociationSetEnd(association.Ends[1], container.EntitySets.First(es => association.Ends[1].EntityType.IsKindOf(es.EntityType))),
}
});
}
}
}
示例8: Fixup
/// <summary>
/// Remove named streams and corresponding features in model for EF provider
/// </summary>
/// <param name="model">The model to fix up</param>
public void Fixup(EntityModelSchema model)
{
foreach (var entityType in model.EntityTypes)
{
entityType.Properties.RemoveAll(p => p.IsStream());
}
}
示例9: Fixup
/// <summary>
/// Adds the EntitySet information to an action or validates that it has an entitySet Path
/// </summary>
/// <param name="model">The model to fix up</param>
public void Fixup(EntityModelSchema model)
{
foreach (Function f in model.Functions.Where(f => f.IsAction() && f.ReturnType != null))
{
var serviceOperationAnnotation = f.Annotations.OfType<ServiceOperationAnnotation>().Single();
// If someone has set the entitySetPath or the entitySet name then we don't need to update anything
if (serviceOperationAnnotation.EntitySetPath != null || serviceOperationAnnotation.EntitySetName != null)
{
continue;
}
EntityDataType entityDataType = f.ReturnType as EntityDataType;
var collectionDataType = f.ReturnType as CollectionDataType;
if (collectionDataType != null)
{
entityDataType = collectionDataType.ElementDataType as EntityDataType;
}
if (entityDataType != null)
{
var possibleMatch = model.EntityContainers.Single().EntitySets.Where(es => entityDataType.Definition.IsKindOf(es.EntityType)).ToList();
ExceptionUtilities.Assert(possibleMatch.Count == 1, string.Format(CultureInfo.InvariantCulture, "Cannot resolve function '{0}' to one EntitySet, possible matches were '{1}'", f.Name, string.Join(",", possibleMatch.Select(es => es.Name))));
serviceOperationAnnotation.EntitySetName = possibleMatch.Single().Name;
}
}
}
示例10: Improve
/// <summary>
/// Improve the model if goal not yet met
/// </summary>
/// <param name="model">Model to improve</param>
public override void Improve(EntityModelSchema model)
{
foreach (var et in model.EntityTypes
.Where(c => c.BaseType == null)
.Where(c => c.AllKeyProperties.Count() < this.MinNumberOfKeysPerEntities))
{
int numOfKeyPropertiesNeeded = this.MinNumberOfKeysPerEntities;
if (this.MinNumberOfKeysPerEntities != this.MaxNumberOfKeysPerEntities)
{
numOfKeyPropertiesNeeded = this.Random.NextFromRange(this.MinNumberOfKeysPerEntities, this.MaxNumberOfKeysPerEntities);
}
// Consume the existing properties...
foreach (MemberProperty mp in et.Properties.Where(p => p.IsPrimaryKey == false).SkipWhile(q => q.PropertyType is ComplexDataType))
{
if (et.AllKeyProperties.Count() < numOfKeyPropertiesNeeded)
{
mp.IsPrimaryKey = true;
}
else
{
break;
}
}
// Create new properties and make them key...
while (et.AllKeyProperties.Count() < numOfKeyPropertiesNeeded)
{
et.Properties.Add(new MemberProperty()
{
IsPrimaryKey = true
});
}
}
}
示例11: GenerateObjectLayer
/// <summary>
/// Generates the object layer for the given model
/// </summary>
/// <param name="compileUnit">The compile unit to add code to</param>
/// <param name="model">The model to base the object layer on</param>
public void GenerateObjectLayer(CodeCompileUnit compileUnit, EntityModelSchema model)
{
var namespaces = model.EntityTypes.Select(et => et.NamespaceName).Union(model.ComplexTypes.Select(ct => ct.NamespaceName)).Union(model.Functions.Select(f => f.NamespaceName)).Distinct().ToList();
foreach (string namespaceName in namespaces)
{
CodeNamespace codeNamespace = Code.AddNamespace(compileUnit, namespaceName);
foreach (string ns in this.GetNamespaceImports())
{
codeNamespace.ImportNamespace(ns);
}
foreach (ComplexType type in model.ComplexTypes.Where(ct => ct.NamespaceName == namespaceName))
{
if (this.ShouldGenerateTypeDefinition(type))
{
this.DeclareComplexType(type, codeNamespace.DeclareType(type.Name));
}
}
foreach (EntityType type in model.EntityTypes.Where(ct => ct.NamespaceName == namespaceName))
{
if (this.ShouldGenerateTypeDefinition(type))
{
this.DeclareEntityType(type, codeNamespace.DeclareType(type.Name));
}
}
this.AddFunctionsInNamespaceIfRequired(namespaceName, codeNamespace, model.Functions);
}
}
示例12: GenerateEntityClasses
/// <summary>
/// Generates POCO entities based on the supplied model
/// </summary>
/// <param name="model">Model to generate classes from</param>
/// <returns>Generated code files</returns>
public IEnumerable<FileContents<string>> GenerateEntityClasses(EntityModelSchema model)
{
ExceptionUtilities.CheckArgumentNotNull(model, "model");
PocoAnnotator.Annotate(model, this.PocoOption);
List<FileContents<string>> results = new List<FileContents<string>>();
foreach (var ns in model.EntityTypes.Select(e => e.NamespaceName).Concat(model.EnumTypes.Select(e => e.NamespaceName)).Concat(model.ComplexTypes.Select(e => e.NamespaceName)).Distinct())
{
var codeUnit = new CodeCompileUnit();
CodeNamespace codeNamespace = codeUnit.AddNamespace(ns);
codeNamespace.ImportNamespace("System.Collections.Generic");
foreach (var type in model.ComplexTypes.Where(e => e.NamespaceName == ns))
{
codeNamespace.Types.Add(this.BuildType(type));
}
foreach (var type in model.EntityTypes.Where(e => e.NamespaceName == ns))
{
codeNamespace.Types.Add(this.BuildType(type));
}
foreach (var type in model.EnumTypes.Where(e => e.NamespaceName == ns))
{
codeNamespace.Types.Add(this.BuildType(type));
}
string code = this.GenerateCodeFromCompileUnit(codeUnit);
results.Add(new FileContents<string>(ns + this.language.FileExtension, code));
}
return results;
}
示例13: Visit
/// <summary>
/// Visits a model
/// </summary>
/// <param name="model">model to visit</param>
public void Visit(EntityModelSchema model)
{
foreach (var entity in model.EntityTypes)
{
this.VisitEntityType(entity);
}
foreach (var complex in model.ComplexTypes)
{
this.VisitComplexType(complex);
}
foreach (var association in model.Associations)
{
this.VisitAssociationType(association);
}
foreach (var container in model.EntityContainers)
{
this.VisitEntityContainer(container);
}
foreach (var function in model.Functions)
{
this.VisitFunction(function);
}
foreach (var enumType in model.EnumTypes)
{
this.VisitEnumType(enumType);
}
}
示例14: Fixup
/// <summary>
/// Performs the fixup for all items that have Name and Namespace.
/// </summary>
/// <param name="model">Model to perform fixup on.</param>
public void Fixup(EntityModelSchema model)
{
foreach (INamedItem item in this.GetAllNamedItems(model))
{
this.FixupNamedItem(item);
}
}
示例15: Fixup
/// <summary>
/// Sets the EntityContainer to default DataServiceConfiguration settings if not specified
/// Default settings are all permissions for all entitysets
/// All permissions for ServiceOperations
/// Visible permissions for all actions
/// and UseVerboseErrors = true
/// </summary>
/// <param name="model">The model to fix up</param>
public void Fixup(EntityModelSchema model)
{
EntityContainer container = model.GetDefaultEntityContainer();
if (!container.Annotations.OfType<EntitySetRightsAnnotation>().Any())
{
container.Annotations.Add(new EntitySetRightsAnnotation() { Value = EntitySetRights.All });
}
if (!container.Annotations.OfType<ServiceOperationRightsAnnotation>().Any())
{
container.Annotations.Add(new ServiceOperationRightsAnnotation() { Value = ServiceOperationRights.All });
}
if (!container.Annotations.OfType<ActionOperationRightsAnnotation>().Any())
{
container.Annotations.Add(new ActionOperationRightsAnnotation() { Value = ActionOperationRights.Invoke });
}
DataServiceConfigurationAnnotation dataServiceConfigurationAnnotation = container.GetDataServiceConfiguration();
if (dataServiceConfigurationAnnotation == null)
{
dataServiceConfigurationAnnotation = new DataServiceConfigurationAnnotation();
dataServiceConfigurationAnnotation.UseVerboseErrors = true;
container.Annotations.Add(dataServiceConfigurationAnnotation);
}
DataServiceBehaviorAnnotation dataServiceBehaviorAnnotation = container.GetDataServiceBehavior();
if (dataServiceBehaviorAnnotation == null)
{
dataServiceBehaviorAnnotation = new DataServiceBehaviorAnnotation();
dataServiceBehaviorAnnotation.MaxProtocolVersion = this.MaxProtocolVersion;
container.Annotations.Add(dataServiceBehaviorAnnotation);
}
}