public static void PopulateFields(nHydrate.Dsl.nHydrateModel model, DataImport.View view, nHydrate.Dsl.View newView) { //newView.Fields.Clear(); foreach (var field in view.FieldList) { var newField = newView.Fields.FirstOrDefault(x => x.Name.ToLower() == field.Name.ToLower()); if (newField == null) { newField = new nHydrate.Dsl.ViewField(model.Partition); newField.Name = field.Name; newView.Fields.Add(newField); //Correct for invalid identifiers if (!nHydrate.Dsl.ValidationHelper.ValidCodeIdentifier(newField.Name)) { newField.CodeFacade = nHydrate.Dsl.ValidationHelper.MakeCodeIdentifier(newField.Name, string.Empty); } } newField.Length = field.Length; newField.Nullable = field.Nullable; newField.DataType = (DataTypeConstants)Enum.Parse(typeof(DataTypeConstants), field.DataType.ToString()); newField.Default = field.DefaultValue; newField.Scale = field.Scale; } //Remove the fields that need to be remove newView.Fields.Remove(x => !view.FieldList.Select(a => a.Name.ToLower()).ToList().Contains(x.Name.ToLower())); }
public static nHydrate.DataImport.SQLObject ToDatabaseObject(this View item) { var retval = new DataImport.View(); retval.Name = item.Name; retval.Schema = item.Schema; retval.SQL = item.SQL; //Fields foreach (var f in item.Fields) { retval.FieldList.Add(new nHydrate.DataImport.Field() { DataType = (System.Data.SqlDbType)Enum.Parse(typeof(System.Data.SqlDbType), f.DataType.ToString(), true), DefaultValue = f.Default, Length = f.Length, Name = f.Name, Nullable = f.Nullable, Scale = f.Scale, }); } return(retval); }