Inheritance: nHydrate.Generator.Common.GeneratorFramework.BaseModelObject, IModelObject
 public SQLSelectStoredProcedureTemplate(ModelRoot model, CustomStoredProcedure currentStoredProcedure, bool useSingleFile, StringBuilder grantSB)
     : base(model)
 {
     _currentStoredProcedure = currentStoredProcedure;
     _useSingleFile = useSingleFile;
     _grantSB = grantSB;
 }
Ejemplo n.º 2
0
		public NewModelWizardForm(ModelRoot root)
			: this()
		{
			_root = root;
			txtCompanyName.Text = _root.CompanyName;
			txtProjectName.Text = _root.ProjectName;
		}
Ejemplo n.º 3
0
            public static string GetBody(Table table, ModelRoot model)
            {
                try
                {
                    var allColumns = new List<Column>();
                    foreach (var column in table.GetColumnsFullHierarchy().Where(x => x.Generated).OrderBy(x => x.Name))
                    {
                        if (!(column.DataType == System.Data.SqlDbType.Binary ||
                            column.DataType == System.Data.SqlDbType.Image ||
                            column.DataType == System.Data.SqlDbType.NText ||
                            column.DataType == System.Data.SqlDbType.Text ||
                            column.DataType == System.Data.SqlDbType.Timestamp ||
                            column.DataType == System.Data.SqlDbType.Udt ||
                            column.DataType == System.Data.SqlDbType.VarBinary ||
                            column.DataType == System.Data.SqlDbType.Variant ||
                        column.DataType == System.Data.SqlDbType.Money))
                        {
                            allColumns.Add(column);
                        }
                    }

                    if (allColumns.Count != 0)
                    {
                        return BuildStoredProcedure(table, model, allColumns);
                    }

                    return "";

                }
                catch (Exception ex)
                {
                    throw new Exception(table.DatabaseName + ": Failed on generation of paging select statement", ex);
                }
            }
Ejemplo n.º 4
0
		public XSDSchemaTemplate(ModelRoot model, string schemaName, string rawFileName, bool droprelations)
			: base(model)
		{
			_rawFileName = rawFileName;
			_schemaName = schemaName;
			_droprelations = droprelations;
		}
 public SQLStoredProcedureViewAllTemplate(ModelRoot model, CustomView view, bool singleFile, StringBuilder grantSB)
     : base(model)
 {
     _view = view;
     _singleFile = singleFile;
     _grantSB = grantSB;
 }
Ejemplo n.º 6
0
 public static string GetTableDatabaseName(ModelRoot model, Table table)
 {
     var retval = model.Database.TablePrefix;
     if (!string.IsNullOrEmpty(retval))
         return retval + "_" + table.DatabaseName;
     else
         return table.DatabaseName;
 }
		public void Populate(ModelRoot model)
		{
			_model = model;
			_model.PropertyChanged += new PropertyChangedEventHandler(_model_PropertyChanged);
			this.LoadControls();

			#region Hook events
			txtCompanyName.Leave += new EventHandler(txtCompanyName_Leave);
			txtCompanyName.Enter += new EventHandler(txtCompanyName_Enter);
			txtCompanyName.KeyDown += new KeyEventHandler(txtCompanyName_KeyDown);

			txtCopyright.Leave += new EventHandler(txtCopyright_Leave);
			txtCopyright.Enter += new EventHandler(txtCopyright_Enter);
			txtCopyright.KeyDown += new KeyEventHandler(txtCopyright_KeyDown);

			txtDefaultNamespace.Leave += new EventHandler(txtDefaultNamespace_Leave);
			txtDefaultNamespace.Enter += new EventHandler(txtDefaultNamespace_Enter);
			txtDefaultNamespace.KeyDown += new KeyEventHandler(txtDefaultNamespace_KeyDown);

			txtProjectName.Leave += new EventHandler(txtProjectName_Leave);
			txtProjectName.Enter += new EventHandler(txtProjectName_Enter);
			txtProjectName.KeyDown += new KeyEventHandler(txtProjectName_KeyDown);

			txtStoredProcPrefix.Leave += new EventHandler(txtStoredProcPrefix_Leave);
			txtStoredProcPrefix.Enter += new EventHandler(txtStoredProcPrefix_Enter);
			txtStoredProcPrefix.KeyDown += new KeyEventHandler(txtStoredProcPrefix_KeyDown);

			txtVersion.Leave += new EventHandler(txtVersion_Leave);
			txtVersion.Enter += new EventHandler(txtVersion_Enter);
			txtVersion.KeyDown += new KeyEventHandler(txtVersion_KeyDown);

			chkCustomChangeEvents.CheckStateChanged += new EventHandler(chkCustomChangeEvents_CheckStateChanged);
			chkSupprtLegacySearch.CheckStateChanged += new EventHandler(chkSupprtLegacySearch_CheckStateChanged);
			chkTransformNames.CheckStateChanged += new EventHandler(chkTransformNames_CheckStateChanged);
			chkUseUTC.CheckStateChanged += new EventHandler(chkUseUTC_CheckStateChanged);
			#endregion

			#region Setup Tooltips
			toolTip1.SetToolTip(txtCompanyName, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "CompanyName"));
			toolTip1.SetToolTip(txtCopyright, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "Copyright"));
			toolTip1.SetToolTip(txtDefaultNamespace, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "DefaultNamespace"));
			toolTip1.SetToolTip(txtProjectName, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "ProjectName"));
			toolTip1.SetToolTip(txtStoredProcPrefix, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "StoredProcedurePrefix"));
			toolTip1.SetToolTip(txtVersion, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "Version"));
			toolTip1.SetToolTip(chkCustomChangeEvents, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "EnableCustomChangeEvents"));
			toolTip1.SetToolTip(chkSupprtLegacySearch, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "SupportLegacySearchObject"));
			toolTip1.SetToolTip(chkTransformNames, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "TransformNames"));
			toolTip1.SetToolTip(chkUseUTC, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "UseUTCTime"));
			toolTip1.SetToolTip(cboSQLServerType, ReflectionHelper.GetPropertyAttributeDescriptionValue(_model, "SQLServerType"));
			#endregion

		}
Ejemplo n.º 8
0
        public static string GetSQLCreateTable(ModelRoot model, Table table)
        {
            try
            {
                if (table.TypedTable == TypedTableConstants.EnumOnly)
                    return string.Empty;

                var sb = new StringBuilder();
                var tableName = Globals.GetTableDatabaseName(model, table);

                sb.AppendLine("--CREATE TABLE [" + table.DatabaseName + "]");
                sb.AppendLine("if not exists(select * from sysobjects where name = '" + tableName + "' and xtype = 'U')");
                sb.AppendLine("CREATE TABLE [" + table.GetSQLSchema() + "].[" + tableName + "] (");

                var firstLoop = true;
                foreach (var column in table.GeneratedColumns.OrderBy(x => x.SortOrder))
                {
                    if (!firstLoop) sb.AppendLine(",");
                    else firstLoop = false;
                    sb.Append("\t" + AppendColumnDefinition(column, allowDefault: true, allowIdentity: true));
                }
                AppendModifiedAudit(model, table, sb);
                AppendCreateAudit(model, table, sb);
                AppendTimestamp(model, table, sb);
                AppendTenantField(model, table, sb);

                //Emit PK
                var tableIndex = table.TableIndexList.FirstOrDefault(x => x.PrimaryKey);
                if (tableIndex != null)
                {
                    var indexName = "PK_" + table.DatabaseName.ToUpper();
                    sb.AppendLine(",");
                    sb.AppendLine("\t" + "CONSTRAINT [" + indexName + "] PRIMARY KEY " + (tableIndex.Clustered ? "CLUSTERED" : "NONCLUSTERED"));
                    sb.AppendLine("\t" + "(");
                    sb.AppendLine("\t\t" + Globals.GetSQLIndexField(table, tableIndex));
                    sb.AppendLine("\t" + ")");
                }
                else
                    sb.AppendLine();

                sb.AppendLine(")");
                return sb.ToString();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 9
0
		public static void AppendCopyrightInSQL(StringBuilder sb, ModelRoot model)
		{
			if (!string.IsNullOrEmpty(model.Copyright))
			{
				sb.AppendLine("--Copyright (c) " + DateTime.Now.Year + " " + model.CompanyName + ", All Rights Reserved");

				var temp = model.Copyright.Replace("\r\n", "\n");
				temp = temp.Replace("\r", "\n");
				temp = temp.Replace("%year%", DateTime.Now.Year.ToString());
				var arr = temp.Split('\n');
				foreach (var s in arr)
				{
					sb.AppendLine("--" + s);
				}
				sb.AppendLine();
			}
		}
Ejemplo n.º 10
0
		public ColumnCodeFacadeUpdateForm(ReferenceCollection columnCollection, ModelRoot modelRoot, FieldSettingConstants fieldSetting)
			: this()
		{
			_columnCollection = columnCollection;
			_modelRoot = modelRoot;
			_fieldSetting = fieldSetting;

			if (_fieldSetting == FieldSettingConstants.Name)
			{
				this.Text = "Update Field";
			}
			else if (_fieldSetting == FieldSettingConstants.Name)
			{
				this.Text = "Update CodeFacade";
			}

			try
			{
				ModelCacheFile cacheFile = null;
				if (modelRoot != null) cacheFile = new ModelCacheFile(modelRoot.GeneratorProject);
				else cacheFile = new ModelCacheFile(((ModelRoot)columnCollection.Root).GeneratorProject);
				if (!string.IsNullOrEmpty(cacheFile.CodeFacadeSettings))
				{
					var document = new XmlDocument();
					document.LoadXml(cacheFile.CodeFacadeSettings);
					var containerNode = document.DocumentElement.ChildNodes[0];
					optPrefix.Checked = XmlHelper.GetAttributeValue(containerNode, "prefixChecked", optPrefix.Checked);
					txtPrefix.Text = XmlHelper.GetAttributeValue(containerNode, "prefix", txtPrefix.Text);
					chkReplaceText.Checked = XmlHelper.GetAttributeValue(containerNode, "replaceText", chkReplaceText.Checked);
					txtReplaceSource.Text = XmlHelper.GetAttributeValue(containerNode, "replaceSource", txtReplaceSource.Text);
					txtReplaceTarget.Text = XmlHelper.GetAttributeValue(containerNode, "replaceTarget", txtReplaceTarget.Text);
					optUpcase.Checked = XmlHelper.GetAttributeValue(containerNode, "upcase", optUpcase.Checked);
					optUnderscore.Checked = XmlHelper.GetAttributeValue(containerNode, "underscore", optUnderscore.Checked);
					chkSkip2Caps.Checked = XmlHelper.GetAttributeValue(containerNode, "TwoCaps", chkSkip2Caps.Checked);
				}
			}
			catch (Exception ex)
			{
				throw;
			}

			this.UpdateForm();
		}
        private void AppendFullTemplate(StringBuilder sb, Table table, ModelRoot model)
        {
            try
            {
                var moduleSuffix = string.Empty;
                if (!string.IsNullOrEmpty(_model.ModuleName))
                    moduleSuffix = _model.ModuleName + "_";

                sb.AppendLine("if exists(select * from sys.objects where name = '" + GetStoredProcedureName(table, model, moduleSuffix) + "' and type = 'P' and type_desc = 'SQL_STORED_PROCEDURE')");
                sb.AppendLine("	drop procedure [" + table.GetSQLSchema() + "].[" + GetStoredProcedureName(table, model, moduleSuffix) + "]");
                sb.AppendLine("GO");
                sb.AppendLine();

                //Just drop the procedure if no CRUD SP
                if (!_model.Database.UseGeneratedCRUD)
                    return;

                sb.AppendLine("CREATE PROCEDURE [" + table.GetSQLSchema() + "].[" + GetStoredProcedureName(table, model, moduleSuffix) + "]");
                sb.AppendLine("(");
                sb.AppendLine(BuildParameterList(table, model));
                sb.AppendLine(")");
                sb.AppendLine("AS");
                sb.AppendLine("SET NOCOUNT OFF;");
                sb.AppendLine();
                sb.Append(SQLGeneratedBodyHelper.SQLInsertBusinessObjectBody(table, model));
                sb.AppendLine("GO");
                sb.AppendLine();
                if (model.Database.GrantExecUser != string.Empty)
                {
                    sb.AppendFormat("GRANT EXECUTE ON [" + table.GetSQLSchema() + "].[{0}] TO [{1}]", GetStoredProcedureName(table, model, moduleSuffix), model.Database.GrantExecUser).AppendLine();
                    sb.AppendLine("GO");
                    sb.AppendLine();
                }

            }
            catch (Exception ex)
            {
                throw;
            }

        }
		public DatasiteMasterScriptTemplate(ModelRoot model, string templateLocation)
			: base(model)
		{
			_templateLocation = templateLocation;
		}
		public ComplexTypesSPExtenderTemplate(ModelRoot model, CustomStoredProcedure item)
			: base(model)
		{
			_item = item;
		}
Ejemplo n.º 14
0
		public StyleSheetTemplate(ModelRoot model, string templateLocation)
			: base(model)
		{
			_templateLocation = templateLocation;
		}
 public ViewEntityGeneratedTemplate(ModelRoot model, CustomView currentTable)
     : base(model)
 {
     _item = currentTable;
 }
		public ActionTypesExtenderTemplate(ModelRoot model, CustomStoredProcedure storedProcedure)
			: base(model)
		{
			_storedProc = storedProcedure;
		}
Ejemplo n.º 17
0
 public SQLHelperGeneratedTemplate(ModelRoot model)
     : base(model)
 {
 }
 public LINQExtenderTemplate(ModelRoot model)
     : base(model)
 {
 }
Ejemplo n.º 19
0
 public SQLUpdateComponentTemplate(ModelRoot model, TableComponent currentComponent)
 {
     _model = model;
     _currentComponent = currentComponent;
 }
Ejemplo n.º 20
0
		public DatasiteTableListTemplate(ModelRoot model, string templateLocation)
			: base(model)
		{
			_templateLocation = templateLocation;
		}
Ejemplo n.º 21
0
		public SQLSelectViewTemplate(ModelRoot model, CustomView currentView, StringBuilder grantSB)
		{
			_model = model;
			_currentView = currentView;
			_grantSB = grantSB;
		}
 public ComplexTypesFuncGeneratedTemplate(ModelRoot model, Function item)
     : base(model)
 {
     _item = item;
 }
Ejemplo n.º 23
0
        private nHydrate.Generator.Models.ModelRoot CreatePOCOModel(nHydrateModel model, Microsoft.VisualStudio.Modeling.Diagrams.Diagram diagram)
        {
            try
            {
                var root = new nHydrate.Generator.Models.ModelRoot(null);
                root.EnableCustomChangeEvents = model.EmitChangeScripts;
                root.CompanyName               = model.CompanyName;
                root.EmitSafetyScripts         = model.EmitSafetyScripts;
                root.DefaultNamespace          = model.DefaultNamespace;
                root.ProjectName               = model.ProjectName;
                root.SupportLegacySearchObject = false;
                root.UseUTCTime = model.UseUTCTime;
                root.Version    = model.Version;
                root.Database.ResetKey(model.Id.ToString());
                root.OutputTarget = string.Empty; //model.OutputTarget;
                //These have the same mapping values flags so we need convert to int and then convert to the other enumeration
                root.TenantColumnName                = model.TenantColumnName;
                root.TenantPrefix                    = model.TenantPrefix;
                root.Database.CreatedByColumnName    = model.CreatedByColumnName;
                root.Database.CreatedDateColumnName  = model.CreatedDateColumnName;
                root.Database.ModifiedByColumnName   = model.ModifiedByColumnName;
                root.Database.ModifiedDateColumnName = model.ModifiedDateColumnName;
                root.Database.TimestampColumnName    = model.TimestampColumnName;
                root.Database.GrantExecUser          = model.GrantUser;

                #region Load the entities
                foreach (var entity in model.Entities)
                {
                    #region Table Info
                    var newTable = root.Database.Tables.Add();
                    newTable.ResetKey(entity.Id.ToString());
                    newTable.ResetId(HashString(newTable.Key));
                    newTable.AllowCreateAudit   = entity.AllowCreateAudit;
                    newTable.AllowModifiedAudit = entity.AllowModifyAudit;
                    newTable.AllowTimestamp     = entity.AllowTimestamp;
                    newTable.AssociativeTable   = entity.IsAssociative;
                    newTable.CodeFacade         = entity.CodeFacade;
                    newTable.DBSchema           = entity.Schema;
                    newTable.Description        = entity.Summary;
                    newTable.Immutable          = entity.Immutable;
                    newTable.TypedTable         = (nHydrate.Generator.Models.TypedTableConstants)Enum.Parse(typeof(nHydrate.Generator.Models.TypedTableConstants), entity.TypedEntity.ToString(), true);
                    newTable.Name = entity.Name;
                    newTable.GeneratesDoubleDerived = entity.GeneratesDoubleDerived;
                    newTable.IsTenant = entity.IsTenant;
                    #endregion

                    #region Load the fields for this entity
                    var fieldList = entity.Fields.ToList();
                    foreach (var field in fieldList.OrderBy(x => x.SortOrder))
                    {
                        var newColumn = root.Database.Columns.Add();
                        newColumn.ResetKey(field.Id.ToString());
                        newColumn.ResetId(HashString(newColumn.Key));
                        newColumn.AllowNull      = field.Nullable;
                        newColumn.CodeFacade     = field.CodeFacade;
                        newColumn.ComputedColumn = field.IsCalculated;
                        newColumn.DataType       = (System.Data.SqlDbType)Enum.Parse(typeof(System.Data.SqlDbType), field.DataType.ToString());
                        newColumn.Default        = field.Default;
                        newColumn.DefaultIsFunc  = field.DefaultIsFunc;
                        newColumn.Description    = field.Summary;
                        newColumn.Formula        = field.Formula;
                        newColumn.Identity       = (nHydrate.Generator.Models.IdentityTypeConstants)Enum.Parse(typeof(nHydrate.Generator.Models.IdentityTypeConstants), field.Identity.ToString());
                        newColumn.IsIndexed      = field.IsIndexed;
                        newColumn.IsReadOnly     = field.IsReadOnly;
                        newColumn.IsUnique       = field.IsUnique;
                        newColumn.Length         = field.Length;
                        newColumn.Name           = field.Name;
                        newColumn.ParentTableRef = newTable.CreateRef(newTable.Key);
                        newColumn.PrimaryKey     = field.IsPrimaryKey;
                        newColumn.Scale          = field.Scale;
                        newColumn.SortOrder      = field.SortOrder;
                        newColumn.Obsolete       = field.Obsolete;
                        newTable.Columns.Add(newColumn.CreateRef(newColumn.Key));
                    }
                    #endregion

                    #region Indexes

                    var indexList = entity.Indexes.ToList();
                    foreach (var index in indexList)
                    {
                        var indexColumns = index.IndexColumns.Where(x => x.GetField() != null).ToList();
                        if (indexColumns.Count > 0)
                        {
                            var newIndex = new nHydrate.Generator.Models.TableIndex(newTable.Root)
                            {
                                Description = index.Summary,
                                IsUnique    = index.IsUnique,
                                Clustered   = index.Clustered,
                                PrimaryKey  = (index.IndexType == IndexTypeConstants.PrimaryKey)
                            };
                            newTable.TableIndexList.Add(newIndex);
                            newIndex.ResetKey(index.Id.ToString());
                            newIndex.ResetId(HashString(newIndex.Key));
                            newIndex.ImportedName = index.ImportedName;

                            //Add index columns
                            foreach (var ic in indexColumns.OrderBy(x => x.SortOrder).ThenBy(x => x.GetField().Name))
                            {
                                var field     = ic.GetField();
                                var newColumn = new nHydrate.Generator.Models.TableIndexColumn(newTable.Root)
                                {
                                    Ascending = ic.Ascending, FieldID = field.Id
                                };
                                newIndex.IndexColumnList.Add(newColumn);
                            }
                        }
                    }

                    #endregion

                    #region Static Data
                    //Determine how many rows there are
                    var orderKeyList = entity.StaticDatum.Select(x => x.OrderKey).Distinct().ToList();
                    var rowCount     = orderKeyList.Count;

                    //Create a OLD static data row for each one
                    for (var ii = 0; ii < rowCount; ii++)
                    {
                        //For each row create N cells one for each column
                        var rowEntry            = new nHydrate.Generator.Models.RowEntry(newTable.Root);
                        var staticDataFieldList = fieldList.Where(x => !x.DataType.IsBinaryType() && x.DataType != DataTypeConstants.Timestamp).ToList();
                        for (var jj = 0; jj < staticDataFieldList.Count; jj++)
                        {
                            var cellEntry = new nHydrate.Generator.Models.CellEntry(newTable.Root);
                            var column    = newTable.GetColumns().ToList()[jj];
                            cellEntry.ColumnRef = column.CreateRef(column.Key);

                            var currentColumn = fieldList.FirstOrDefault(x => x.Id == new Guid(column.Key));
                            if (currentColumn != null)
                            {
                                var dataum = entity.StaticDatum.FirstOrDefault(x =>
                                                                               x.ColumnKey == currentColumn.Id &&
                                                                               x.OrderKey == orderKeyList[ii]);

                                if (dataum != null)
                                {
                                    cellEntry.Value = dataum.Value;
                                    cellEntry.ResetKey(dataum.Id.ToString());
                                }

                                //Add the cell to the row
                                rowEntry.CellEntries.Add(cellEntry);
                            }
                        }
                        newTable.StaticData.Add(rowEntry);
                    }
                    #endregion
                }

                #endregion

                #region Relations
                {
                    var relationConnectors = diagram.NestedChildShapes.Where(x => x is EntityAssociationConnector).Cast <EntityAssociationConnector>().ToList();
                    foreach (var shape in relationConnectors)
                    {
                        if (shape is EntityAssociationConnector)
                        {
                            var connector = shape as EntityAssociationConnector;
                            var parent    = connector.FromShape.ModelElement as Entity;
                            var child     = connector.ToShape.ModelElement as Entity;

                            var relation  = connector.ModelElement as EntityHasEntities;
                            var fieldList = model.RelationFields.Where(x => x.RelationID == relation.Id);

                            var parentTable = root.Database.Tables.FirstOrDefault(x => x.Name == parent.Name);
                            var childTable  = root.Database.Tables.FirstOrDefault(x => x.Name == child.Name);

                            //If we found both parent and child tables...
                            if (parentTable != null && childTable != null && !childTable.IsInheritedFrom(parentTable))
                            {
                                var isValidRelation = true;
                                if (isValidRelation)
                                {
                                    var newRelation = root.Database.Relations.Add();
                                    newRelation.ResetKey((connector.ModelElement as nHydrate.Dsl.EntityHasEntities).InternalId.ToString());
                                    newRelation.ResetId(HashString(newRelation.Key));
                                    newRelation.ParentTableRef = parentTable.CreateRef(parentTable.Key);
                                    newRelation.ChildTableRef  = childTable.CreateRef(childTable.Key);
                                    newRelation.RoleName       = ((EntityHasEntities)connector.ModelElement).RoleName;
                                    switch (relation.DeleteAction)
                                    {
                                    case DeleteActionConstants.Cascade:
                                        newRelation.DeleteAction = Relation.DeleteActionConstants.Cascade;
                                        break;

                                    case DeleteActionConstants.NoAction:
                                        newRelation.DeleteAction = Relation.DeleteActionConstants.NoAction;
                                        break;

                                    case DeleteActionConstants.SetNull:
                                        newRelation.DeleteAction = Relation.DeleteActionConstants.SetNull;
                                        break;
                                    }

                                    newRelation.Enforce = relation.IsEnforced;

                                    //Create the column links
                                    foreach (var columnSet in fieldList)
                                    {
                                        var field1 = parent.Fields.FirstOrDefault(x => x.Id == columnSet.SourceFieldId);
                                        var field2 = child.Fields.FirstOrDefault(x => x.Id == columnSet.TargetFieldId);

                                        var column1 = parentTable.GetColumnsFullHierarchy().FirstOrDefault(x => x.Name == field1.Name);
                                        var column2 = childTable.GetColumnsFullHierarchy().FirstOrDefault(x => x.Name == field2.Name);

                                        newRelation.ColumnRelationships.Add(new nHydrate.Generator.Models.ColumnRelationship(root)
                                        {
                                            ParentColumnRef = column1.CreateRef(column1.Key),
                                            ChildColumnRef  = column2.CreateRef(column2.Key),
                                        }
                                                                            );
                                    }

                                    //Actually add the relation to the collection
                                    if (newRelation.ColumnRelationships.Count > 0)
                                    {
                                        parentTable.Relationships.Add(newRelation.CreateRef(newRelation.Key));
                                    }
                                }
                            }
                        }
                    }
                } //inner block

                #endregion

                #region Views
                foreach (var view in model.Views)
                {
                    var newView = root.Database.CustomViews.Add();
                    newView.ResetKey(view.Id.ToString());
                    newView.ResetId(HashString(newView.Key));
                    newView.CodeFacade             = view.CodeFacade;
                    newView.DBSchema               = view.Schema;
                    newView.Description            = view.Summary;
                    newView.Name                   = view.Name;
                    newView.SQL                    = view.SQL;
                    newView.GeneratesDoubleDerived = view.GeneratesDoubleDerived;

                    foreach (var field in view.Fields)
                    {
                        var newField = root.Database.CustomViewColumns.Add();
                        newField.ResetKey(field.Id.ToString());
                        newField.ResetId(HashString(newField.Key));
                        newField.AllowNull    = field.Nullable;
                        newField.CodeFacade   = field.CodeFacade;
                        newField.DataType     = (System.Data.SqlDbType)Enum.Parse(typeof(System.Data.SqlDbType), field.DataType.ToString());
                        newField.Default      = field.Default;
                        newField.Description  = field.Summary;
                        newField.IsPrimaryKey = field.IsPrimaryKey;
                        newField.Length       = field.Length;
                        newField.Name         = field.Name;
                        newField.Scale        = field.Scale;
                        newView.Columns.Add(newField.CreateRef(newField.Key));
                        newField.ParentViewRef = newView.CreateRef(newView.Key);
                    }
                }
                #endregion

                return(root);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 public SQLUpdateBusinessObjectTemplate(ModelRoot model, Table currentTable)
 {
     _model = model;
     _currentTable = currentTable;
 }
 public ContextMockExtenderTemplate(ModelRoot model)
     : base(model)
 {
 }
 public UpgradeUnversionedScriptTemplate(ModelRoot model)
     : base(model)
 {
 }
 public IncludeTreeLINQExtenderTemplate(ModelRoot model)
     : base(model)
 {
 }
Ejemplo n.º 28
0
		public BaseScriptTemplate(ModelRoot model)
			: base(model)
		{
		}
		public AuditEntityGeneratedTemplate(ModelRoot model, Table currentTable)
			: base(model)
		{
			_item = currentTable;
		}
Ejemplo n.º 30
0
 public EFCodeFirstBaseTemplate(ModelRoot model)
     : base(model)
 {
 }
		public ViewEntityGeneratedTemplate(ModelRoot model, CustomView view)
			: base(model)
		{
			_item = view;
		}