public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            PropertyInfo info = (PropertyInfo)conceptInfo;

            PropertyHelper.GenerateCodeForType(info, codeBuilder, "string");
        }
Ejemplo n.º 2
0
 public void GenerateCode(IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
 {
     PropertyHelper.GenerateCodeForType((PropertyInfo)conceptInfo, codeBuilder, "int?");
 }
Ejemplo n.º 3
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.GetSimplePropertyName()) + @", "
                                                       + CsUtility.QuotedString(ReferencePropertyConstraintDatabaseDefinition.GetConstraintName(info)) + @"))
                    ((Rhetos.UserException)interpretedException).SystemMessage = " + CsUtility.QuotedString(systemMessage) + @";
                ";
                    codeBuilder.InsertCode(onDeleteInterpretSqlError, WritableOrmDataStructureCodeGenerator.OnDatabaseErrorTag, info.Referenced);
                }
            }
        }