public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { var info = (UniqueReferenceInfo)conceptInfo; if (DslUtility.IsQueryable(info.Extension) && DslUtility.IsQueryable(info.Base)) { DataStructureQueryableCodeGenerator.AddNavigationProperty(codeBuilder, info.Extension, csPropertyName: "Base", propertyType: "Common.Queryable." + info.Base.Module.Name + "_" + info.Base.Name); DataStructureQueryableCodeGenerator.AddNavigationProperty(codeBuilder, info.Base, csPropertyName: info.ExtensionPropertyName(), propertyType: "Common.Queryable." + info.Extension.Module.Name + "_" + info.Extension.Name); } if (UniqueReferenceDatabaseDefinition.IsSupported(info) && info.Extension is IOrmDataStructure && info.Base is IWritableOrmDataStructure) { var ormDataStructure = (IOrmDataStructure)info.Extension; string systemMessage = $"DataStructure:{info.Extension.FullName},Property:ID,Referenced:{info.Base.FullName}"; string onDeleteInterpretSqlError = @"if (interpretedException is Rhetos.UserException && Rhetos.Utilities.MsSqlUtility.IsReferenceErrorOnDelete(interpretedException, " + CsUtility.QuotedString(ormDataStructure.GetOrmSchema() + "." + ormDataStructure.GetOrmDatabaseObject()) + @", " + CsUtility.QuotedString("ID") + @", " + CsUtility.QuotedString(UniqueReferenceDatabaseDefinition.GetConstraintName(info)) + @")) ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @"; "; codeBuilder.InsertCode(onDeleteInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.Base); } }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { ReferencePropertyInfo info = (ReferencePropertyInfo)conceptInfo; var referenceGuid = new PropertyInfo { DataStructure = info.DataStructure, Name = info.Name + "ID" }; PropertyHelper.GenerateCodeForType(referenceGuid, codeBuilder, "Guid?"); PropertyHelper.GenerateStorageMapping(referenceGuid, codeBuilder, "System.Data.SqlDbType.UniqueIdentifier"); if (DslUtility.IsQueryable(info.DataStructure) && DslUtility.IsQueryable(info.Referenced)) { DataStructureQueryableCodeGenerator.AddNavigationProperty(codeBuilder, info.DataStructure, csPropertyName: info.Name, propertyType: "Common.Queryable." + info.Referenced.Module.Name + "_" + info.Referenced.Name); } if (ReferencePropertyDbConstraintInfo.IsSupported(info) && info.DataStructure is IOrmDataStructure && info.Referenced is IOrmDataStructure) { var ormDataStructure = (IOrmDataStructure)info.DataStructure; var referencedOrmDataStructure = (IOrmDataStructure)info.Referenced; string systemMessage = $"DataStructure:{info.DataStructure.FullName},Property:{info.Name}ID,Referenced:{info.Referenced.FullName}"; if (info.DataStructure is IWritableOrmDataStructure) { string onEnterInterpretSqlError = @"if (interpretedException is Rhetos.UserException && Rhetos.Utilities.MsSqlUtility.IsReferenceErrorOnInsertUpdate(interpretedException, " + CsUtility.QuotedString(referencedOrmDataStructure.GetOrmSchema() + "." + referencedOrmDataStructure.GetOrmDatabaseObject()) + @", " + CsUtility.QuotedString("ID") + @", " + CsUtility.QuotedString(ReferencePropertyConstraintDatabaseDefinition.GetConstraintName(info)) + @")) ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @"; "; codeBuilder.InsertCode(onEnterInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.DataStructure); if (info.Referenced == info.DataStructure) { codeBuilder.InsertCode($@"if (entity.{info.Name}ID != null && entity.{info.Name}ID != entity.ID) yield return entity.{info.Name}ID.Value; ", WritableOrmDataStructureCodeGenerator.PersistenceStorageMapperDependencyResolutionTag, info.DataStructure); } } if (info.Referenced is IWritableOrmDataStructure) { string onDeleteInterpretSqlError = @"if (interpretedException is Rhetos.UserException && Rhetos.Utilities.MsSqlUtility.IsReferenceErrorOnDelete(interpretedException, " + CsUtility.QuotedString(ormDataStructure.GetOrmSchema() + "." + ormDataStructure.GetOrmDatabaseObject()) + @", " + CsUtility.QuotedString(info.GetSimplePropertyName()) + @", " + CsUtility.QuotedString(ReferencePropertyConstraintDatabaseDefinition.GetConstraintName(info)) + @")) ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @"; "; codeBuilder.InsertCode(onDeleteInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.Referenced); } } }
public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder) { var info = (LinkedItemsInfo)conceptInfo; string propertyType = string.Format("IList<Common.Queryable.{0}_{1}>", info.ReferenceProperty.DataStructure.Module.Name, info.ReferenceProperty.DataStructure.Name); if (DslUtility.IsQueryable(info.ReferenceProperty.DataStructure) && DslUtility.IsQueryable(info.DataStructure)) { DataStructureQueryableCodeGenerator.AddNavigationProperty(codeBuilder, info.DataStructure, csPropertyName: info.Name, propertyType: propertyType); } }