/// <summary> /// Initialize a new GeoLocationEntities object. /// </summary> public GeoLocationEntities(string connectionString) : base(Util.ConvertNormalCS2EF(connectionString)) { InstanceKey = Guid.NewGuid(); _contextStartup = new EFDAL.ContextStartup(null, true); ResetContextStartup(); try { var builder = new System.Data.Odbc.OdbcConnectionStringBuilder(Util.StripEFCS2Normal(this.Database.Connection.ConnectionString)); var timeoutValue = "30"; if (builder.ContainsKey("connect timeout")) { timeoutValue = (string)builder["connect timeout"]; } else if (builder.ContainsKey("connection timeout")) { timeoutValue = (string)builder["connection timeout"]; } var v = Convert.ToInt32(timeoutValue); if (v > 0) { this.CommandTimeout = v; } } catch { } this.OnContextCreated(); }
internal static string ConvertNormalCS2EFFromConfig(string configSettings, ContextStartup contextStartup) { if (string.IsNullOrEmpty(configSettings)) { return(configSettings); } var arr = configSettings.Split('='); if (arr.Length != 2) { return(configSettings); } if (arr[0] != "name") { return(configSettings); } try { var cs = System.Configuration.ConfigurationManager.ConnectionStrings[arr[1]].ConnectionString; if (!cs.StartsWith("metadata=")) { return(ConvertNormalCS2EF(cs, contextStartup)); } return(configSettings); } catch { return(configSettings); } }
public static int UpdateData( Expression <Func <K, P> > select, Expression <Func <K, bool> > where, P newValue, string leafTable, GetDatabaseFieldNameDelegate getField, bool hasModifyAudit, ContextStartup startup, string connectionString ) { using (var connection = Gravitybox.GeoLocation.EFDAL.DBHelper.GetConnection(Gravitybox.GeoLocation.EFDAL.Util.StripEFCS2Normal(connectionString))) { connection.Open(); return(UpdateData( select, where, newValue, leafTable, getField, hasModifyAudit, startup, connection, null)); } }
/// <summary> /// Initialize a new GeoLocationEntities object with an audit modifier. /// </summary> public GeoLocationEntities(ContextStartup contextStartup, string connectionString) : base(Util.ConvertNormalCS2EF(connectionString, contextStartup)) { InstanceKey = Guid.NewGuid(); _contextStartup = contextStartup; ResetContextStartup(); this.ContextOptions.LazyLoadingEnabled = contextStartup.AllowLazyLoading; this.CommandTimeout = contextStartup.CommandTimeout; this.OnContextCreated(); }
internal static string ConvertNormalCS2EF(string connectionString, ContextStartup contextStartup) { return(ConvertNormalCS2EFFromConfig(connectionString, contextStartup)); }
public static int UpdateData( Expression <Func <K, P> > select, Expression <Func <K, bool> > where, P newValue, string leafTable, GetDatabaseFieldNameDelegate getField, bool hasModifyAudit, ContextStartup startup, IDbConnection connection, System.Data.Common.DbTransaction transaction ) { if (startup == null) { startup = new ContextStartup(null); } using (var dc = new DataContext(connection)) { var template = dc.GetTable <K>(); using (var cmd = BusinessEntityQuery.GetCommand <K, P>(dc, template, select, where)) { if (!startup.DefaultTimeout && startup.CommandTimeout > 0) { cmd.CommandTimeout = startup.CommandTimeout; } else { cmd.CommandTimeout = DEFAULTTIMEOUT; } if (transaction != null) { cmd.Transaction = transaction; } var parser = LinqSQLParser.Create(cmd.CommandText, LinqSQLParser.ObjectTypeConstants.Table); var fieldName = parser.GetSelectClause(); var sql = "UPDATE [" + parser.GetTableAlias(fieldName, leafTable) + "]\r\n"; sql += "SET [" + parser.GetTableAlias(fieldName, leafTable) + "].[" + fieldName + "] = @newValue\r\n"; if (hasModifyAudit && (fieldName != "ModifiedBy")) { sql += ", [" + parser.GetTableAlias(fieldName, leafTable) + "].[ModifiedBy] = NULL\r\n"; } if (hasModifyAudit && (fieldName != "ModifiedDate")) { sql += ", [" + parser.GetTableAlias(fieldName, leafTable) + "].[ModifiedDate] = sysdatetime()\r\n"; } sql += parser.GetFromClause(new QueryOptimizer()) + "\r\n"; sql += parser.GetWhereClause(); sql += ";select @@rowcount"; sql = "set ansi_nulls off;" + sql; cmd.CommandText = sql; if (newValue == null) { cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("newValue", System.DBNull.Value)); } else { cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("newValue", newValue)); } object p = cmd.ExecuteScalar(); return((int)p); } } }