public virtual void OnDelete() { foreach (Property property in DbLinq.Objects <Property>().Where(x => x.Item == this).ToList()) { property.Delete(); } }
protected virtual void WriteDataContextProcedures(CodeWriter writer, DbLinq.Schema.Dbml.Database schema, GenerationContext context) { foreach (var procedure in schema.Functions) { WriteDataContextProcedure(writer, procedure, context); } }
public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context) { using (writer.WriteRegion(string.Format("{0} handling", typeof(INotifyPropertyChanging).Name))) { const string eventName = "PropertyChanging"; // do not change, part of INotifyPropertyChanging const string emptyArgs = "emptyChangingEventArgs"; // event writer.WriteEvent(SpecificationDefinition.Public, eventName, typeof(PropertyChangingEventHandler).Name); writer.WriteLine(); // empty event arg writer.WriteField(SpecificationDefinition.Private | SpecificationDefinition.Static, writer.GetAssignmentExpression(emptyArgs, writer.GetNewExpression( writer.GetMethodCallExpression(typeof(PropertyChangingEventArgs).Name, "\"\""))), typeof(PropertyChangingEventArgs).Name); // method using (writer.WriteMethod(SpecificationDefinition.Protected | SpecificationDefinition.Virtual, sendPropertyChangingMethod, null)) { using (writer.WriteIf(writer.GetDifferentExpression(eventName, writer.GetNullExpression()))) { writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(eventName, writer.GetThisExpression(), emptyArgs))); } } } }
public void RefreshProducts() { this.Products.Data = DbLinq.Objects <Product>() .OrderBy(x => x.Name) .ThenBy(x => x.GetObjectNo()) .ToList(); }
public override void OnDelete() { foreach (Module module in DbLinq.Objects <Module>().Where(x => x.Product == this).ToList()) { module.Delete(); } base.OnDelete(); }
public static GltfRef TryCreatingGltfRef(string ifcObjectGuid, B5dProjectNode project, B5dObject b5dObject) { var existingRef = DbLinq.Objects <GltfRef>().FirstOrDefault(o => o.BelongsTo == b5dObject); if (existingRef != null) { return(existingRef); } string documentsDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); string conversionPath = $"{documentsDirectory}\\Conversions"; var projectName = project.Name; var b5dObjectType = b5dObject.TypeSpecifier.ToLower(); b5dObjectType = b5dObjectType.Replace("ifc", ""); // The ifcTo3DTiles conversion renames WallStandardCase to Wall b5dObjectType = b5dObjectType.Replace("wallstandardcase", "wall"); var ifcDirectory = $"{conversionPath}\\Conversion_{projectName}\\IFCs"; var files = Directory.GetFiles(ifcDirectory); var ifcFiles = files.Where(f => f.ToLower().Contains(b5dObjectType)); if (ifcFiles.Count() == 0) { return(null); } foreach (string ifcFilePath in ifcFiles) { var ifcModel = IfcStore.Open(ifcFilePath); var ifcObject = ifcModel.Instances.FirstOrDefault() as IIfcObject; if (ifcObject.GlobalId == ifcObjectGuid) { var gltfFilepath = ifcFilePath.Replace("IFCs", "GLTFs").Replace(".ifc", ".gltf"); FileStream gltfFile = File.Open(gltfFilepath, FileMode.Open); var filename = Path.GetFileName(gltfFilepath); if (ifcObject != null && gltfFile != null) { var fileRef = new GltfRef() { BelongsTo = b5dObject, Extension = "gltf", FileId = ifcObjectGuid, FileName = filename, MimeType = "model/gltf+json", FileSize = gltfFilepath.Length, }; return(fileRef); } break; } } return(null); }
public void TestGetEnumerator_IEnumerable() { Scheduling.RunTask(() => { var enumerable = (IEnumerable)DbLinq.Objects <Person>(); var enumerator = enumerable.GetEnumerator(); Assert.NotNull(enumerator); }).Wait(); }
public void Init() { this.DataTable = new DataTableBuilder <DataTableRow>() .WithDataSource(DbLinq.Objects <Person>(), data => data.WithConverter(CreateDataTableRow)) .WithColumns(columns => columns .AddColumn(b => b.FirstName, column => column.DisplayName("First Name").Sortable().Filterable()) .AddColumn(b => b.LastName, column => column.Sortable().DisplayName("Last Name")) .AddColumn(b => b.Email, column => column.Filterable().Sortable().DisplayName("Email"))) .WithInitialPageSize(20) .Build(); }
public void OnDelete() { foreach (Branch branch in DbLinq.Objects <Branch>().Where(x => x.Parent == this).ToList()) { branch.Delete(); } foreach (Commit commit in this.OwnCommits.ToList()) { commit.Delete(); } }
protected override string WriteProcedureBodyMethodCall(CodeWriter writer, DbLinq.Schema.Dbml.Function procedure, GenerationContext context) { // picrap: there may be some more elegant ways to invoke a stored procedure, because ExecuteMethodCall is // for internal use only const string result = "result"; var parametersBuilder = new StringBuilder(); foreach (var parameter in procedure.Parameters) { if (parameter.DirectionIn) parametersBuilder.AppendFormat(", {0}", parameter.Name); } writer.WriteLine(string.Format("var {0} = ExecuteMethodCall(this, (MethodInfo)MethodBase.GetCurrentMethod(){1});", result, parametersBuilder)); return result; }
public static void PostProcess_DB(DbLinq.Schema.Dbml.Database schema) { if (schema == null) return; //sort tables, parent tables first // picrap: how useful was this? //TableSorter sorter = new TableSorter(schema.Tables); //schema.Tables.Sort(sorter); foreach (var tbl in schema.Tables) { PostProcess_Table(tbl); } }
public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context) { using (writer.WriteRegion(string.Format("{0} handling", typeof(INotifyPropertyChanged).Name))) { const string eventName = "PropertyChanged"; // do not change, part of INotifyPropertyChanged const string propertyNameName = "propertyName"; // event writer.WriteEvent(SpecificationDefinition.Public, eventName, typeof(PropertyChangedEventHandler).Name); writer.WriteLine(); // method using (writer.WriteMethod(SpecificationDefinition.Protected | SpecificationDefinition.Virtual, sendPropertyChangedMethod, null, new ParameterDefinition { Name = propertyNameName, Type = typeof(string) })) { using (writer.WriteIf(writer.GetDifferentExpression(eventName, writer.GetNullExpression()))) { writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(eventName, writer.GetThisExpression(), writer.GetNewExpression(writer.GetMethodCallExpression(typeof(PropertyChangedEventArgs).Name, propertyNameName))))); } } } }
public override void WritePropertyAfterSet(CodeWriter writer, DbLinq.Schema.Dbml.Column property, GenerationContext context) { writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(sendPropertyChangedMethod, writer.GetLiteralValue(property.Member)))); writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression("On" + property.Member + "Changed"))); }
protected virtual void WriteProcedureBodyOutParameter(CodeWriter writer, DbLinq.Schema.Dbml.Parameter parameter, string result, int parameterIndex, GenerationContext context) { string p = writer.GetMethodCallExpression(writer.GetMemberExpression(result, "GetParameterValue"), parameterIndex.ToString()); string cp = writer.GetCastExpression(p, parameter.Type, true); writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(parameter.Name, cp))); }
protected virtual string GetProcedureName(DbLinq.Schema.Dbml.Function procedure) { return procedure.Method ?? procedure.Name; }
public Northwind(System.Data.IDbConnection connection, DbLinq.Vendor.IVendor vendor) : base(connection, vendor) { }
protected virtual void WriteProcedureBodyOutParameters(CodeWriter writer, DbLinq.Schema.Dbml.Function procedure, string result, GenerationContext context) { int parameterIndex = 0; foreach (var parameter in procedure.Parameters) { if (parameter.DirectionOut) WriteProcedureBodyOutParameter(writer, parameter, result, parameterIndex, context); parameterIndex++; } }
protected virtual void WriteProcedureBodyReturnValue(CodeWriter writer, DbLinq.Schema.Dbml.Function procedure, string result, GenerationContext context) { Type returnType = GetProcedureType(procedure); if (returnType != null) writer.WriteLine(writer.GetReturnStatement(writer.GetCastExpression(writer.GetMemberExpression(result, "ReturnValue"), writer.GetLiteralType(returnType), true))); }
void WriteObject_Version (DbLinq.Schema.Dbml.Version ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem) { System.Type type = ob.GetType (); if (type == typeof(DbLinq.Schema.Dbml.Version)) { } else { throw CreateUnknownTypeException (ob); } if (writeWrappingElem) { WriteStartElement (element, namesp, ob); } if (needType) WriteXsiType("Version", "http://schemas.microsoft.com/linqtosql/dbml/2007"); Writer.WriteString (GetEnumValue_Version (ob)); if (writeWrappingElem) WriteEndElement (ob); }
protected virtual ParameterDefinition GetProcedureParameter(DbLinq.Schema.Dbml.Parameter parameter) { var parameterDefinition = new ParameterDefinition(); parameterDefinition.Name = parameter.Name; parameterDefinition.Type = GetType(parameter.Type, false); switch (parameter.Direction) { case DbLinq.Schema.Dbml.ParameterDirection.In: parameterDefinition.SpecificationDefinition |= SpecificationDefinition.In; break; case DbLinq.Schema.Dbml.ParameterDirection.Out: parameterDefinition.SpecificationDefinition |= SpecificationDefinition.Out; break; case DbLinq.Schema.Dbml.ParameterDirection.InOut: parameterDefinition.SpecificationDefinition |= SpecificationDefinition.Ref; break; default: throw new ArgumentOutOfRangeException(); } parameterDefinition.Attribute = NewAttributeDefinition<ParameterAttribute>(); parameterDefinition.Attribute["Name"] = parameter.Name; parameterDefinition.Attribute["DbType"] = parameter.DbType; return parameterDefinition; }
protected virtual ParameterDefinition[] GetProcedureParameters(DbLinq.Schema.Dbml.Function procedure) { var parameters = new List<ParameterDefinition>(); foreach (var parameter in procedure.Parameters) parameters.Add(GetProcedureParameter(parameter)); return parameters.ToArray(); }
protected virtual Type GetProcedureType(DbLinq.Schema.Dbml.Function procedure) { Type type = null; if (procedure.Return != null) { type = GetType(procedure.Return.Type, false); } bool isDataShapeUnknown = procedure.ElementType == null && procedure.BodyContainsSelectStatement && !procedure.IsComposable; if (isDataShapeUnknown) { //if we don't know the shape of results, and the proc body contains some selects, //we have no choice but to return an untyped DataSet. // //TODO: either parse proc body like microsoft, //or create a little GUI tool which would call the proc with test values, to determine result shape. type = typeof(DataSet); } return type; }
string GetEnumValue_AutoSync (DbLinq.Schema.Dbml.AutoSync val) { switch (val) { case DbLinq.Schema.Dbml.AutoSync.Never: return "Never"; case DbLinq.Schema.Dbml.AutoSync.OnInsert: return "OnInsert"; case DbLinq.Schema.Dbml.AutoSync.OnUpdate: return "OnUpdate"; case DbLinq.Schema.Dbml.AutoSync.Always: return "Always"; case DbLinq.Schema.Dbml.AutoSync.Default: return "Default"; default: throw CreateInvalidEnumValueException ((long) val, typeof (DbLinq.Schema.Dbml.AutoSync).FullName); } }
public override void WritePropertyBeforeSet(CodeWriter writer, DbLinq.Schema.Dbml.Column property, GenerationContext context) { writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression("On" + property.Member + "Changing", "value"))); writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(sendPropertyChangingMethod))); }
private Expressions.ExpressionTranslator GetTranslator(DbLinq.Vendor.ISqlProvider provider) { var p = provider as DbLinq.Vendor.Implementation.SqlProvider; if (p != null) return p.GetTranslator(); return new ExpressionTranslator(); }
private static List<SubscriptionItem> TransformSubscriptionItems(DbLinq.Data.Linq.EntitySet<PersistenceStorage.SubscriptionItem> entitySet) { List<SubscriptionItem> list = new List<SubscriptionItem>(); foreach (var item in entitySet) { list.Add(TransformSubscriptionItem(item)); } return list; }
public static void PostProcess_Table(DbLinq.Schema.Dbml.Table table) { // picrap: this is processed earlier //table.Member = Util.FormatTableName(table.Type.Name, util.PluralEnum.Pluralize); //table.Type.Name = Util.FormatTableName(table.Type.Name, util.PluralEnum.Singularize); //if (mmConfig.renamesFile != null) //{ // table.Member = Util.Rename(table.Member); //} foreach (DbLinq.Schema.Dbml.Column col in table.Type.Columns) { if (col.Member == table.Type.Name) col.Member = "Contents"; //rename field Alltypes.Alltypes to Alltypes.Contents // picrap processed earlier //col.Storage = "_" + col.Name; // picrap moved to CSCodeWriter //if (CSharp.IsCsharpKeyword(col.Storage)) // col.Storage += "_"; //rename column 'int' -> 'int_' //if (CSharp.IsCsharpKeyword(col.Member)) // col.Member += "_"; //rename column 'int' -> 'int_' } Dictionary<string, bool> knownAssocs = new Dictionary<string, bool>(); foreach (DbLinq.Schema.Dbml.Association assoc in table.Type.Associations) { // picrap: processed earlier //assoc.Type = Util.FormatTableName(assoc.Type, util.PluralEnum.Singularize); //util.PluralEnum pluralEnum = assoc.IsForeignKey // ? util.PluralEnum.Singularize // : util.PluralEnum.Pluralize; //referring to parent: "public Employee Employee" //referring to child: "public EntityMSet<Product> Products" //assoc.Member = Util.FormatTableName(assoc.Member, pluralEnum); if (assoc.Member == table.Type.Name) { string thisKey = assoc.ThisKey ?? "_TODO_L35"; //self-join: rename field Employees.Employees to Employees.RefersToEmployees assoc.Member = thisKey + assoc.Member; } if (knownAssocs.ContainsKey(assoc.Member)) { //this is the Andrus test case in Pgsql: // create table t1 ( private int primary key); // create table t2 ( f1 int references t1, f2 int references t1 ); assoc.Member += "_" + assoc.Name; } // picrap: handled previously //if (mmConfig.renamesFile != null) //{ // assoc.Member = Util.Rename(assoc.Member); //} //if (assoc.Member == "employeeterritories" || assoc.Member == "Employeeterritories") // assoc.Member = "EmployeeTerritories"; //hack to help with Northwind knownAssocs[assoc.Member] = true; } }
public override void WritePropertyAfterSet(CodeWriter writer, DbLinq.Schema.Dbml.Column property, GenerationContext context) { writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(ModifiedName, writer.GetLiteralValue(true)))); }
protected abstract string WriteProcedureBodyMethodCall(CodeWriter writer, DbLinq.Schema.Dbml.Function procedure, GenerationContext context);
private const string ModifiedName = "IsModified"; // mandatory value, since the IModified interface requires this member public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context) { writer.WriteCommentLine("IModified backing field"); writer.WritePropertyWithBackingField(SpecificationDefinition.Public, ModifiedName, writer.GetLiteralType(typeof(bool))); writer.WriteLine(); }
string GetEnumValue_Cardinality (DbLinq.Schema.Dbml.Cardinality val) { switch (val) { case DbLinq.Schema.Dbml.Cardinality.One: return "One"; case DbLinq.Schema.Dbml.Cardinality.Many: return "Many"; default: throw CreateInvalidEnumValueException ((long) val, typeof (DbLinq.Schema.Dbml.Cardinality).FullName); } }
protected override void WriteDataContextTable(CodeWriter writer, DbLinq.Schema.Dbml.Table table) { writer.WriteLine("public Table<{1}> {0} {{ get {{ return GetTable<{1}>(); }} }}", table.Member, table.Type.Name); }
string GetEnumValue_Version (DbLinq.Schema.Dbml.Version val) { switch (val) { case DbLinq.Schema.Dbml.Version.Current: return "Current"; case DbLinq.Schema.Dbml.Version.Original: return "Original"; default: throw CreateInvalidEnumValueException ((long) val, typeof (DbLinq.Schema.Dbml.Version).FullName); } }
public Spring(System.Data.IDbConnection connection, DbLinq.Vendor.IVendor vendor) : base(connection, vendor) { }
/// <summary> /// guess which fields are populated by sequences. /// Mark them with [AutoGenId]. /// </summary> public static void GuessSequencePopulatedFields(DbLinq.Schema.Dbml.Database schema) { if (schema == null) return; foreach (DbLinq.Schema.Dbml.Table tbl in schema.Tables) { var q = from col in tbl.Type.Columns where col.IsPrimaryKey select col; List<DbLinq.Schema.Dbml.Column> cols = q.ToList(); bool canBeFromSequence = cols.Count == 1 && (!cols[0].CanBeNull) && (cols[0].DbType == "NUMBER" || cols[0].DbType == "INTEGER"); if (canBeFromSequence) { //TODO: query sequences, store sequence name. //in the meantime, assume naming convention similar to 'Products_seq' cols[0].IsDbGenerated = true; } } }
public AllTypes(System.Data.IDbConnection connection, DbLinq.Vendor.IVendor vendor) : base(connection, vendor) { }
private List<Tenant> ConvertTenants(DbLinq.Data.Linq.EntitySet<PersistenceStorage.Tenant> entitySet) { List<Tenant> tenants = new List<Tenant>(); foreach (PersistenceStorage.Tenant t in entitySet) { Tenant tenant = new Tenant(); tenant.Id = t.ID; tenant.Name = t.Name; if(t.UpperScaleLimit.HasValue) tenant.UpperScaleLimit = (int)t.UpperScaleLimit; if (t.ScalingFactor.HasValue) tenant.ScalingFactor = (int)t.ScalingFactor; tenants.Add(tenant); } return tenants; }