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?");

            if (DslUtility.IsQueryable(info.DataStructure) && DslUtility.IsQueryable(info.Referenced))
            {
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.DataStructure,
                                                                                          csPropertyName: info.Name,
                                                                                          propertyType: "Common.Queryable." + info.Referenced.Module.Name + "_" + info.Referenced.Name,
                                                                                          additionalSetterCode: info.Name + "ID = value != null ? (Guid?)value.ID : null;");
            }

            if (info.DataStructure is IOrmDataStructure && info.Referenced is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().HasOptional(t => t.{2}).WithMany().HasForeignKey(t => t.{2}ID);\r\n            ",
                                  info.DataStructure.Module.Name, info.DataStructure.Name, info.Name),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.DataStructure is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.{2});\r\n            ",
                                  info.DataStructure.Module.Name, info.DataStructure.Name, info.Name),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
        }
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (UniqueReferenceInfo)conceptInfo;

            if (DslUtility.IsQueryable(info.Extension) && DslUtility.IsQueryable(info.Base))
            {
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Extension,
                                                                                          csPropertyName: "Base",
                                                                                          propertyType: "Common.Queryable." + info.Base.Module.Name + "_" + info.Base.Name,
                                                                                          additionalSetterCode: "ID = value != null ? value.ID : Guid.Empty;");
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Base,
                                                                                          csPropertyName: info.ExtensionPropertyName(),
                                                                                          propertyType: "Common.Queryable." + info.Extension.Module.Name + "_" + info.Extension.Name,
                                                                                          additionalSetterCode: null);
            }

            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)
        {
            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.AddNavigationPropertyWithBackingField(codeBuilder, info.DataStructure,
                                                                                          csPropertyName: info.Name,
                                                                                          propertyType: propertyType,
                                                                                          additionalSetterCode: null);
            }

            if (info.ReferenceProperty.DataStructure is IOrmDataStructure && info.DataStructure is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().HasOptional(t => t.{2}).WithMany(t => t.{3}).HasForeignKey(t => t.{2}ID);\r\n            ",
                                  info.ReferenceProperty.DataStructure.Module.Name, info.ReferenceProperty.DataStructure.Name, info.ReferenceProperty.Name, info.Name),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.DataStructure is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.{2});\r\n            ",
                                  info.DataStructure.Module.Name, info.DataStructure.Name, info.Name),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
        }
Example #4
0
        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.AddNavigationPropertyWithBackingField(codeBuilder, info.DataStructure,
                                                                                          csPropertyName: info.Name,
                                                                                          propertyType: "Common.Queryable." + info.Referenced.Module.Name + "_" + info.Referenced.Name,
                                                                                          additionalSetterCode: info.Name + "ID = value != null ? (Guid?)value.ID : null;");
            }

            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 = (UniqueReferenceInfo)conceptInfo;

            if (DslUtility.IsQueryable(info.Extension) && DslUtility.IsQueryable(info.Base))
            {
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Extension,
                                                                                          csPropertyName: "Base",
                                                                                          propertyType: "Common.Queryable." + info.Base.Module.Name + "_" + info.Base.Name,
                                                                                          additionalSetterCode: "ID = value != null ? value.ID : Guid.Empty;");
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Base,
                                                                                          csPropertyName: info.ExtensionPropertyName(),
                                                                                          propertyType: "Common.Queryable." + info.Extension.Module.Name + "_" + info.Extension.Name,
                                                                                          additionalSetterCode: null);
            }

            if (info.Extension is IOrmDataStructure && info.Base is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().HasRequired(t => t.Base).WithOptional(t => t.{2});\r\n            ",
                                  info.Extension.Module.Name, info.Extension.Name, info.ExtensionPropertyName()),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.Extension is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.Base);\r\n            ",
                                  info.Extension.Module.Name, info.Extension.Name),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.Base is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.{2});\r\n            ",
                                  info.Base.Module.Name, info.Base.Name, info.ExtensionPropertyName()),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }

            if (UniqueReferenceDatabaseDefinition.IsSupported(info) &&
                info.Extension is IOrmDataStructure &&
                info.Base is IWritableOrmDataStructure)
            {
                var    ormDataStructure          = (IOrmDataStructure)info.Extension;
                string systemMessage             = "DataStructure:" + info.Extension + ",Property:ID,Referenced:" + info.Base;
                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)
        {
            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);
            }
        }
Example #7
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            DataStructureExtendsInfo info = (DataStructureExtendsInfo)conceptInfo;
            var extensionPropertyName     = ExtensionPropertyName(info);

            if (DslUtility.IsQueryable(info.Extension) && DslUtility.IsQueryable(info.Base))
            {
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Extension,
                                                                                          csPropertyName: "Base",
                                                                                          propertyType: "Common.Queryable." + info.Base.Module.Name + "_" + info.Base.Name,
                                                                                          additionalSetterCode: "ID = value != null ? value.ID : Guid.Empty;");
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.Base,
                                                                                          csPropertyName: extensionPropertyName,
                                                                                          propertyType: "Common.Queryable." + info.Extension.Module.Name + "_" + info.Extension.Name,
                                                                                          additionalSetterCode: null);
            }

            if (info.Extension is IOrmDataStructure && info.Base is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().HasRequired(t => t.Base).WithOptional(t => t.{2});\r\n            ",
                                  info.Extension.Module.Name, info.Extension.Name, extensionPropertyName),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.Extension is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.Base);\r\n            ",
                                  info.Extension.Module.Name, info.Extension.Name),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.Base is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.{2});\r\n            ",
                                  info.Base.Module.Name, info.Base.Name, extensionPropertyName),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
        }
Example #8
0
        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?");

            if (DslUtility.IsQueryable(info.DataStructure) && DslUtility.IsQueryable(info.Referenced))
            {
                DataStructureQueryableCodeGenerator.AddNavigationPropertyWithBackingField(codeBuilder, info.DataStructure,
                                                                                          csPropertyName: info.Name,
                                                                                          propertyType: "Common.Queryable." + info.Referenced.Module.Name + "_" + info.Referenced.Name,
                                                                                          additionalSetterCode: info.Name + "ID = value != null ? (Guid?)value.ID : null;");
            }

            if (info.DataStructure is IOrmDataStructure && info.Referenced is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    info.OrmMappingSnippet(),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }
            else if (info.DataStructure is IOrmDataStructure)
            {
                codeBuilder.InsertCode(
                    string.Format("modelBuilder.Entity<Common.Queryable.{0}_{1}>().Ignore(t => t.{2});\r\n            ",
                                  info.DataStructure.Module.Name, info.DataStructure.Name, info.Name),
                    DomInitializationCodeGenerator.EntityFrameworkOnModelCreatingTag);
            }

            if (ReferencePropertyConstraintDatabaseDefinition.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 + ",Property:" + info.Name + "ID,Referenced:" + info.Referenced;

                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 is IWritableOrmDataStructure)
                {
                    string onDeleteInterpretSqlError = @"if (interpretedException is Rhetos.UserException && Rhetos.Utilities.MsSqlUtility.IsReferenceErrorOnDelete(interpretedException, "
                                                       + CsUtility.QuotedString(ormDataStructure.GetOrmSchema() + "." + ormDataStructure.GetOrmDatabaseObject()) + @", "
                                                       + CsUtility.QuotedString(info.Name + "ID") + @", "
                                                       + CsUtility.QuotedString(ReferencePropertyConstraintDatabaseDefinition.GetConstraintName(info)) + @"))
                    ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @";
                ";
                    codeBuilder.InsertCode(onDeleteInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.Referenced);
                }
            }
        }
Example #9
0
        public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            ImplementsQueryableInterfaceInfo info = (ImplementsQueryableInterfaceInfo)conceptInfo;

            DataStructureQueryableCodeGenerator.AddInterfaceAndReference(codeBuilder, info.GetInterfaceType(), info.DataStructure);
        }