public static E2ERelationship ToData(CdmE2ERelationship instance) { return(new E2ERelationship { Name = !string.IsNullOrWhiteSpace(instance.Name) ? instance.Name : null, FromEntity = instance.FromEntity, FromEntityAttribute = instance.FromEntityAttribute, ToEntity = instance.ToEntity, ToEntityAttribute = instance.ToEntityAttribute }); }
public static E2ERelationship ToData(CdmE2ERelationship instance) { return(new E2ERelationship { Name = instance.Name, FromEntity = instance.FromEntity, FromEntityAttribute = instance.FromEntityAttribute, ToEntity = instance.ToEntity, ToEntityAttribute = instance.ToEntityAttribute }); }
public void RelationshipMatchesTableColumnForeignTableConstraint() { CdmEntityRelationshipGenerator generator = BuildCdmEntityRelationshipGenerator(); var fk = new Table("Customer").WithColumn("ID", SqlDbType.Int).GetColumn(); var table = new Table("CustomerAddresses").WithColumn("C_ID", SqlDbType.Int, foreignKey: fk); CdmE2ERelationship relationship = generator.GenerateRelationships(table).First(); Assert.Matches(".*.cdm.json/CustomerAddresses", relationship.FromEntity); Assert.Matches(".*.cdm.json/Customer", relationship.ToEntity); }
/// <summary> /// Check if relationship added or modified. /// </summary> internal static bool IsRelationshipAddedorModified(CdmE2ERelationship entity, IDictionary <string, RelationshipEntity> existingSymsRelationship) { if (entity.Name == null || existingSymsRelationship == null || existingSymsRelationship.Count == 0 || !existingSymsRelationship.ContainsKey(entity.Name)) { return(true); } if (entity.LastFileModifiedTime != null && (entity.LastFileModifiedOldTime != null && entity.LastFileModifiedOldTime < entity.LastFileModifiedTime)) { return(true); } return(false); }
public static E2ERelationship ToData(CdmE2ERelationship instance, ResolveOptions resOpt, CopyOptions options) { return(new E2ERelationship { Name = !string.IsNullOrWhiteSpace(instance.Name) ? instance.Name : null, FromEntity = instance.FromEntity, FromEntityAttribute = instance.FromEntityAttribute, ToEntity = instance.ToEntity, ToEntityAttribute = instance.ToEntityAttribute, ExhibitsTraits = CopyDataUtils.ListCopyData(resOpt, instance.ExhibitsTraits, options) }); }
/// <summary> /// Print the relationship /// </summary> /// <param name="relationship"></param> /// <returns></returns> private static string PrintRelationship(CdmE2ERelationship relationship) { StringBuilder bldr = new StringBuilder(); if (!string.IsNullOrWhiteSpace(relationship?.Name)) { bldr.AppendLine($" Name: {relationship.Name}"); } bldr.AppendLine($" FromEntity: {relationship.FromEntity}"); bldr.AppendLine($" FromEntityAttribute: {relationship.FromEntityAttribute}"); bldr.AppendLine($" ToEntity: {relationship.ToEntity}"); bldr.AppendLine($" ToEntityAttribute: {relationship.ToEntityAttribute}"); bldr.AppendLine(); Console.WriteLine(bldr.ToString()); return(bldr.ToString()); }
public async Task TestSelfReference() { CdmCorpusDefinition cdmCorpus = TestHelper.GetLocalCorpus(testsSubpath, "TestSelfReference"); CdmManifestDefinition manifest = await cdmCorpus.FetchObjectAsync <CdmManifestDefinition>("local:/SelfReference.manifest.cdm.json"); await cdmCorpus.CalculateEntityGraphAsync(manifest); await manifest.PopulateManifestRelationshipsAsync(); Assert.AreEqual(1, manifest.Relationships.Count); CdmE2ERelationship rel = manifest.Relationships[0]; Assert.AreEqual("CustTable.cdm.json/CustTable", rel.FromEntity); Assert.AreEqual("CustTable.cdm.json/CustTable", rel.ToEntity); Assert.AreEqual("FactoringAccountRelationship", rel.FromEntityAttribute); Assert.AreEqual("PaymTermId", rel.ToEntityAttribute); }
public static RelationshipEntity ToData(CdmE2ERelationship instance, string dbName, ResolveOptions resOpt, CopyOptions options, IDictionary <string, RelationshipEntity> relationship = null) { var properties = new Dictionary <string, JToken>(); if (instance.ExhibitsTraits != null && instance.ExhibitsTraits.Count > 0) { properties["cdm:exhibitsTraits"] = JToken.FromObject(CopyDataUtils.ListCopyData(resOpt, instance.ExhibitsTraits, options)); } var relationshipProperties = new RelationshipProperties { NamespaceProperty = new NamespaceModel { DatabaseName = dbName }, FromTableName = Utils.ExtractTableNameFromEntityPath(instance.FromEntity), ToTableName = Utils.ExtractTableNameFromEntityPath(instance.ToEntity), Properties = properties, PublishStatus = PublishStatus.PUBLISHED, RelationshipType = RelationshipType.MANYTOONE }; var relationshipName = instance.Name; if (string.IsNullOrEmpty(instance.Name)) { relationshipName = $"{relationshipProperties.FromTableName}_{relationshipProperties.ToTableName}_relationship"; } relationshipProperties.ColumnRelationshipInformations = new List <ColumnRelationshipInformation>(); relationshipProperties.ColumnRelationshipInformations.Add(new ColumnRelationshipInformation(instance.FromEntityAttribute, instance.ToEntityAttribute)); return(new RelationshipEntity { Name = relationshipName, Properties = relationshipProperties, Type = SASEntityType.RELATIONSHIP }); }
/// <summary> /// Print the relationship /// </summary> /// <param name="relationship"></param> /// <returns></returns> private static string PrintRelationship(CdmE2ERelationship relationship) { StringBuilder bldr = new StringBuilder(); if (!string.IsNullOrWhiteSpace(relationship?.Name)) { bldr.AppendLine($" Name: {relationship.Name}"); } bldr.AppendLine($" FromEntity: {relationship.FromEntity}"); bldr.AppendLine($" FromEntityAttribute: {relationship.FromEntityAttribute}"); bldr.AppendLine($" ToEntity: {relationship.ToEntity}"); bldr.AppendLine($" ToEntityAttribute: {relationship.ToEntityAttribute}"); if (relationship.ExhibitsTraits != null && relationship.ExhibitsTraits.Count != 0) { bldr.AppendLine($" ExhibitsTraits:"); var orderedAppliedTraits = relationship.ExhibitsTraits.AllItems.ToList().OrderBy(x => x.NamedReference); foreach (CdmTraitReferenceBase trait in orderedAppliedTraits) { bldr.AppendLine($" {trait.NamedReference}"); if (trait is CdmTraitReference) { foreach (CdmArgumentDefinition args in (trait as CdmTraitReference).Arguments) { AttributeContextUtil attrCtxUtil = new AttributeContextUtil(); bldr.AppendLine($" {attrCtxUtil.GetArgumentValuesAsString(args)}"); } } } } bldr.AppendLine(); Console.WriteLine(bldr.ToString()); return(bldr.ToString()); }