public virtual int InsertWithPrimaryKey(TEntity entity) { dynamic id; int primaryKeyValue = 0; string query = QB <TEntity> .InsertWithPrimaryKey(); if (Transaction != null) { id = Connection.Query(query, entity, transaction: Transaction).FirstOrDefault(); } else { id = Connection.Query(query, entity).FirstOrDefault(); } if (id != null) { var firstItem = (IDictionary <string, object>)id; foreach (var v in firstItem) { primaryKeyValue = Convert.ToInt32(v.Value); } } return(primaryKeyValue); }
public virtual int Update(T entity) { SetOtherKeyValue(entity); var query = QB <T> .Update(); return(_dbContext.SqlConnection.Query <int>(query, entity).FirstOrDefault()); }
public static SqlPredicate Parse(Expression expression) { var methodCallExpression = expression as MethodCallExpression; if (methodCallExpression != null) { if (methodCallExpression.Method.Name == nameof(string.Contains)) { var memberExpression = methodCallExpression.Object as MemberExpression; return(QB.Like(memberExpression.Member.Name, Expression.Lambda(methodCallExpression.Arguments.First()).Compile().DynamicInvoke())); } else { throw new Exception($"Unsupported method {methodCallExpression.Method.Name} in expression {expression}."); } } var binaryExpression = expression as BinaryExpression; if (binaryExpression == null) { throw new Exception($"Unsupported expression {expression}."); } switch (binaryExpression.NodeType) { case ExpressionType.AndAlso: return(QB.And(Parse(binaryExpression.Left), Parse(binaryExpression.Right))); case ExpressionType.OrElse: return(QB.Or(Parse(binaryExpression.Left), Parse(binaryExpression.Right))); case ExpressionType.NotEqual: var nameAndValue0 = GetColumnNameAndParameterValue(binaryExpression); return(QB.NEq(nameAndValue0.Item1, nameAndValue0.Item2)); case ExpressionType.Equal: var nameAndValue1 = GetColumnNameAndParameterValue(binaryExpression); return(QB.Eq(nameAndValue1.Item1, nameAndValue1.Item2)); case ExpressionType.LessThan: var nameAndValue2 = GetColumnNameAndParameterValue(binaryExpression); return(QB.Le(nameAndValue2.Item1, nameAndValue2.Item2)); case ExpressionType.LessThanOrEqual: var nameAndValue3 = GetColumnNameAndParameterValue(binaryExpression); return(QB.LEq(nameAndValue3.Item1, nameAndValue3.Item2)); case ExpressionType.GreaterThan: var nameAndValue4 = GetColumnNameAndParameterValue(binaryExpression); return(QB.Gr(nameAndValue4.Item1, nameAndValue4.Item2)); case ExpressionType.GreaterThanOrEqual: var nameAndValue5 = GetColumnNameAndParameterValue(binaryExpression); return(QB.GEq(nameAndValue5.Item1, nameAndValue5.Item2)); default: throw new Exception($"Unsupported expression {expression}."); } }
public int Process_LOAN_CL(List <AST_LOAN_CL_TMP> portFolios) { var sql = QB <AST_LOAN_CL_TMP> .Insert(); var affectedRows = Connection.Execute(sql, portFolios); return(affectedRows); }
public virtual int InsertWithoutIdentity(T entity) { SetPrimaryKeyValue(entity); SetOtherKeyValue(entity); var query = QB <T> .InsertWithoutIdentityColumn(); return(_dbContext.SqlConnection.Query <int>(query, entity).FirstOrDefault()); }
public virtual IEnumerable <TEntity> GetAll() { string query = QB <TEntity> .Select(); if (Transaction != null) { return(Connection.Query <TEntity>(query, transaction: Transaction)); } return(Connection.Query <TEntity>(query)); }
public int Process_LOAN_PORTFOLIO(List <AST_RM_PORTFOLIO_TMP> portFolios) { //var sql = @"insert into ERMP.AST_LOAN_PORTFOLIO_TMP (File_Process_ID,ID_of_Area,Name_of_Area,Brn_Code,Branch_Name,ID_of_RM,Name_of_RM,Loan_Acct_No,INS_BY,INS_DATE) // values (:File_Process_ID,:ID_of_Area,:Name_of_Area,:Brn_Code,:Branch_Name,:ID_of_RM,:Name_of_RM,:Loan_Acct_No,:INS_BY,:INS_DATE)"; var sql = QB <AST_RM_PORTFOLIO_TMP> .Insert(); var affectedRows = Connection.Execute(sql, portFolios); return(affectedRows); }
public virtual TEntity Get(int id) { string query = QB <TEntity> .SelectById(id); if (Transaction != null) { return(Connection.Query <TEntity>(query, transaction: Transaction).FirstOrDefault()); } return(Connection.Query <TEntity>(query).FirstOrDefault()); }
internal T SetPrimaryKeyValue(T entity) { var primaryKey = QB <T> .GetPrimaryKeyColumns()[0]; var newIdQuery = QB <T> .GetNewId(); var newId = _dbContext.SqlConnection.Query <int>(newIdQuery, entity).Single(); PropertyInfo propertyInfo = entity.GetType().GetProperty(Convert.ToString(primaryKey)); propertyInfo.SetValue(entity, Convert.ChangeType(newId, propertyInfo.PropertyType), null); return(entity); }
public virtual int Update(TEntity entity) { string query = QB <TEntity> .Update(); if (Transaction != null) { return(Connection.Execute(query, entity, transaction: Transaction)); } else { return(Connection.Execute(query, entity)); } }
public virtual void Delete(int id) { string query = QB <TEntity> .Delete(); string primaryKey = QB <TEntity> .GetPrimaryKeyColumns().FirstOrDefault(); var p = new DynamicParameters(); p.Add("@" + primaryKey, id); if (Transaction != null) { Connection.Execute(query, p, transaction: Transaction); } else { Connection.Execute(query, p); } }
public TEntity Load <TEntity>(object id) where TEntity : new() { if (id is SqlPredicate) { throw new ArgumentException("Entity id was expected but SqlPredicate found. You probably wanted to use Load<TEntity>(QueryBuilder.Create().SetWhereStatement(sqlPredicate))."); } MappingAttribute identityMapping = FindIdentity <TEntity>(); if (identityMapping == null) { throw new Exception(string.Format("Entity {0} has no primary key defined.", typeof(TEntity).Name)); } var results = Load <TEntity>(QueryBuilder.Create().SetWhereStatement(QB.Eq(identityMapping.Name, id))); if (results.Count > 1) { throw new Exception(string.Format("There is more than one record with id {0} of entity {1}.", id, typeof(TEntity).Name)); } return(results.FirstOrDefault()); }
public void PassFootBallToMovingTarget(QB ballThrower, OffPlayer receiver, FootBall footBall, float arcType, float power) { isComplete = true; SetGameManager(); gameManager.AttemptPass(ballThrower, receiver, this, arcType, power); //todo, this is ugly. Probably should be a bool for isComplete if (rb == null) { rb = GetComponent <Rigidbody>(); } //targetPos = GetPositionIn(2, wr); transform.parent = null; rb.useGravity = true; BallisticMotion motion = GetComponent <BallisticMotion>(); Vector3 targetPos = receiver.transform.position; Vector3 diff = targetPos - transform.position; Vector3 diffGround = new Vector3(diff.x, 0f, diff.z); Vector3 fireVel, impactPos; Vector3 velocity = receiver.navMeshAgent.velocity; //FTS Calculations https://github.com/forrestthewoods/lib_fts/tree/master/projects/unity/ballistic_trajectory float gravity; if (Ballistics.solve_ballistic_arc_lateral(transform.position, power, targetPos + Vector3.up, velocity, arcType, out fireVel, out gravity, out impactPos)) { GameObject go = Instantiate(targetMarker, impactPos, Quaternion.LookRotation(ballThrower.transform.position + new Vector3(0, 1, 0))); go.name = "footballMarker"; go.transform.parent = FindObjectOfType <FootBall>().transform; Destroy(go, 2); transform.forward = diffGround; motion.Initialize(transform.position, gravity); motion.AddImpulse(fireVel); gameManager.ThrowTheBall(ballThrower, receiver, this, impactPos, arcType, power, isComplete); //todo the football stores whether the pass is complete or not, not sure if thats a good idea. } //Debug.Log("Firing at " + impactPos); }
public static string buildQueuePO(POInformation p) { string QA, QB; QA = "INSERT INTO PurchaseOrder ("; QB = "VALUES('"; QA = QA + "PO_NUMBER,"; QB = QB + p.OrderNumber + "','"; QA = QA + "PURCHASER,"; QB = QB + p.Purchaser + "','"; QA = QA + "VENDOR,"; QB = QB + p.Vendor + "','"; QA = QA + "PROJECT_NUMBER,"; QB = QB + p.JobNumber + "','"; QA = QA + "PO_DATE,"; QB = QB + p.OrderDate + "','"; QA = QA + "TOTAL,"; QB = QB + p.Total + "','"; QA = QA + "FILE,"; QB = QB + " " + "','"; QA = QA + "NOTES"; QB = QB + p.Note; QA = QA + ")"; QB = QB + "')"; QB.Replace("''", "' '"); return(QA + " " + QB); }
public void Test_QB_Insert_Update() { var person = new { Id = new Guid("cf9fad7a-9775-28b9-7693-11e6ea3b1484"), Name = "John", BirthDate = new DateTime(1975, 03, 17), Version = Environment.TickCount }; string tableName = "CustomTableName"; string n1 = nameof(person.Id); string n2 = nameof(person.Name); string n3 = nameof(person.BirthDate); string n4 = nameof(person.Version); string p1 = $"@#{n1}"; string p2 = $"@#{n2}"; string p3 = $"@#{n3}"; string p4 = $"@#{n4}"; (object, Type)p = default; { // Insert - all properties var query = QB.Insert(person, tableName: tableName.AsSqlName()); string expectedSQL = $"INSERT [{tableName}] ([{n1}],[{n2}],[{n3}],[{n4}]) VALUES ({p1},{p2},{p3},{p4})"; Assert.IsTrue(query.SQL == expectedSQL); Assert.IsTrue(query.ParameterMap.Count == 4); p = query.ParameterMap[p1]; Assert.IsTrue((Guid)p.Item1 == person.Id); Assert.IsTrue(p.Item2 == typeof(Guid)); p = query.ParameterMap[p2]; Assert.IsTrue((string)p.Item1 == person.Name); Assert.IsTrue(p.Item2 == typeof(string)); p = query.ParameterMap[p3]; Assert.IsTrue((DateTime)p.Item1 == person.BirthDate); Assert.IsTrue(p.Item2 == typeof(DateTime)); p = query.ParameterMap[p4]; Assert.IsTrue((int)p.Item1 == person.Version); Assert.IsTrue(p.Item2 == typeof(int)); } { // Insert - excluded properties var query = QB.Insert(person, excludedProperties: n => n == nameof(person.Version), tableName: tableName.AsSqlName()); string expectedSQL = $"INSERT [{tableName}] ([{n1}],[{n2}],[{n3}]) VALUES ({p1},{p2},{p3})"; Assert.IsTrue(query.SQL == expectedSQL); Assert.IsTrue(query.ParameterMap.Count == 3); p = query.ParameterMap[p1]; Assert.IsTrue((Guid)p.Item1 == person.Id); Assert.IsTrue(p.Item2 == typeof(Guid)); p = query.ParameterMap[p2]; Assert.IsTrue((string)p.Item1 == person.Name); Assert.IsTrue(p.Item2 == typeof(string)); p = query.ParameterMap[p3]; Assert.IsTrue((DateTime)p.Item1 == person.BirthDate); Assert.IsTrue(p.Item2 == typeof(DateTime)); } string p5 = $"@w@{n1}"; { // Update - all properties var query = QB.Update(person, tableName: tableName.AsSqlName()); string expectedSQL = $"UPDATE [{tableName}] SET [{n1}]={p1},[{n2}]={p2},[{n3}]={p3},[{n4}]={p4} WHERE [{n1}]={p5}"; Assert.IsTrue(query.SQL == expectedSQL); Assert.IsTrue(query.ParameterMap.Count == 5); p = query.ParameterMap[p1]; Assert.IsTrue((Guid)p.Item1 == person.Id); Assert.IsTrue(p.Item2 == typeof(Guid)); p = query.ParameterMap[p2]; Assert.IsTrue((string)p.Item1 == person.Name); Assert.IsTrue(p.Item2 == typeof(string)); p = query.ParameterMap[p3]; Assert.IsTrue((DateTime)p.Item1 == person.BirthDate); Assert.IsTrue(p.Item2 == typeof(DateTime)); p = query.ParameterMap[p4]; Assert.IsTrue((int)p.Item1 == person.Version); Assert.IsTrue(p.Item2 == typeof(int)); p = query.ParameterMap[p5]; Assert.IsTrue((Guid)p.Item1 == person.Id); Assert.IsTrue(p.Item2 == typeof(Guid)); } { // Update - included properties - one property var query = QB.Update(person, includedProperties: n => n == nameof(person.Name), tableName: tableName.AsSqlName()); string expectedSQL = $"UPDATE [{tableName}] SET [{n2}]={p2} WHERE [{n1}]={p5}"; Assert.IsTrue(query.SQL == expectedSQL); Assert.IsTrue(query.ParameterMap.Count == 2); p = query.ParameterMap[p2]; Assert.IsTrue((string)p.Item1 == person.Name); Assert.IsTrue(p.Item2 == typeof(string)); p = query.ParameterMap[p5]; Assert.IsTrue((Guid)p.Item1 == person.Id); Assert.IsTrue(p.Item2 == typeof(Guid)); } { // Update - included properties - all except two var query = QB.Update(person, includedProperties: n => n != nameof(person.Id) && n != nameof(person.Version), tableName: tableName.AsSqlName()); string expectedSQL = $"UPDATE [{tableName}] SET [{n2}]={p2},[{n3}]={p3} WHERE [{n1}]={p5}"; Assert.IsTrue(query.SQL == expectedSQL); Assert.IsTrue(query.ParameterMap.Count == 3); p = query.ParameterMap[p2]; Assert.IsTrue((string)p.Item1 == person.Name); Assert.IsTrue(p.Item2 == typeof(string)); p = query.ParameterMap[p3]; Assert.IsTrue((DateTime)p.Item1 == person.BirthDate); Assert.IsTrue(p.Item2 == typeof(DateTime)); p = query.ParameterMap[p5]; Assert.IsTrue((Guid)p.Item1 == person.Id); Assert.IsTrue(p.Item2 == typeof(Guid)); } } // Test_QB_Insert_Update()
public DbRepositoryQuery <T> Where(Expression <Func <T, bool> > whereExpression) { var newWhereStatement = Linq2PredicateParser.Parse(whereExpression.Body); QueryBuilder.SetWhereStatement(QueryBuilder.WhereStatement == null ? newWhereStatement : QB.And(QueryBuilder.WhereStatement, newWhereStatement)); return(this); }
public virtual int Delete(T entity) { var query = QB <T> .Delete(); return(_dbContext.SqlConnection.Query <int>(query, entity).FirstOrDefault()); }
public void AttemptPass(QB ballThrower, OffPlayer ballReciever, FootBall ball, float arcType, float power) { passAttempt(ballThrower, ballReciever, ball, arcType, power); }
public void ThrowTheBall(QB ballThrower, OffPlayer ballReciever, FootBall ball, Vector3 impactPos, float arcType, float power, bool isComplete) { onBallThrown(ballThrower, ballReciever, ball, impactPos, arcType, power, isComplete); }
/// <summary> /// Runs a Query in the current working memory. /// </summary> /// <param name="queryLabel">The label of the Query to run.</param> /// <returns>A QueryResultSet containing the results found.</returns> /// <see cref="org.nxbre.ie.rule.QueryResultSet"/> public QueryResultSet RunQuery(string queryLabel) { return(RunQuery(QB.Get(queryLabel), false)); }
/// <summary> /// Runs a Query in the current working memory. /// </summary> /// <param name="queryIndex">The query base index of the Query to run.</param> /// <returns>A QueryResultSet containing the results found.</returns> /// <see cref="org.nxbre.ie.rule.QueryResultSet"/> /// <remarks>It is recommanded to use labelled queries.</remarks> public QueryResultSet RunQuery(int queryIndex) { return(RunQuery(QB.Get(queryIndex), false)); }
/// <summary> /// Loads a rule base. The working memory is reset (all facts are lost). /// </summary> /// <param name="adapter">The Adapter used to read the rule base.</param> /// <param name="businessObjectsBinder">The business object binder that the engine must use.</param> /// <remarks> /// The adapter will be disposed at the end of the method's execution. /// </remarks> /// <see cref="org.nxbre.ie.adapters.IRuleBaseAdapter"/> public void LoadRuleBase(IRuleBaseAdapter adapter, IBinder businessObjectsBinder) { if (HasLogListener) { ForceDispatchLog("NxBRE Inference Engine Rule Base Loading Started, using adapter " + adapter.GetType().FullName, LogEventImpl.INFO); } using (adapter) { // reset the WM WM.PrepareInitialization(); // sets the Binder Binder = businessObjectsBinder; // and pass it to the adapter if needed if (Binder != null) { adapter.Binder = Binder; } // currently only forward chaining is supported direction = adapter.Direction; if (direction == "backward") { throw new BREException("NxBRE does not support backward chaining"); } else if (direction == String.Empty) { if (HasLogListener) { ForceDispatchLog("NxBRE interprets no-direction directive as forward chaining.", LogEventImpl.WARN); } else if (direction == "bidirectional") { if (HasLogListener) { ForceDispatchLog("NxBRE interprets bidirectional as forward chaining.", LogEventImpl.WARN); } else if (direction != "forward") { throw new BREException("NxBRE does not support direction: " + direction); } } } // sets the label label = adapter.Label; // load the Equivalents and IntegrityQueries if the adapter supports it if (adapter is IExtendedRuleBaseAdapter) { equivalents = ((IExtendedRuleBaseAdapter)adapter).Equivalents; if (HasLogListener) { ForceDispatchLog("Loaded " + equivalents.Count + " Equivalents", LogEventImpl.DEBUG); } integrityQueries = ((IExtendedRuleBaseAdapter)adapter).IntegrityQueries; foreach (Query integrityQuery in integrityQueries) { WM.FB.RegisterAtoms(integrityQuery.AtomGroup.AllAtoms); } if (HasLogListener) { ForceDispatchLog("Loaded " + integrityQueries.Count + " IntegrityQueries", LogEventImpl.DEBUG); } } else { equivalents = new ArrayList(); integrityQueries = equivalents; } // instantiate the implication base and the query base ib = new ImplicationBase(); qb = new QueryBase(); // instantiate the related managers mm = new MutexManager(IB); pm = new PreconditionManager(IB); initialized = true; // load queries foreach (Query query in adapter.Queries) { QB.Add(query); WM.FB.RegisterAtoms(query.AtomGroup.AllAtoms); } if (HasLogListener) { ForceDispatchLog("Loaded " + QB.Count + " Queries", LogEventImpl.DEBUG); } // load implications foreach (Implication implication in adapter.Implications) { IB.Add(implication); int nbRA = WM.FB.RegisterAtoms(implication.AtomGroup.AllAtoms); if (HasLogListener) { ForceDispatchLog("Registered: " + nbRA + " body atoms", LogEventImpl.DEBUG); } // modifying implication must run searches based on their deduction, so must register the atom if (implication.Action == ImplicationAction.Modify) { nbRA = WM.FB.RegisterAtoms(implication.Deduction); if (HasLogListener) { ForceDispatchLog("Registered: " + nbRA + " head atoms", LogEventImpl.DEBUG); } } } if (HasLogListener) { ForceDispatchLog("Loaded " + IB.Count + " Implications\n", LogEventImpl.DEBUG); } // load mutexes mm.AnalyzeImplications(); if (HasLogListener) { ForceDispatchLog("Loaded Mutexes\n" + mm.ToString(), LogEventImpl.DEBUG); } // load preconditions pm.AnalyzeImplications(); if (HasLogListener) { ForceDispatchLog("Loaded Preconditions\n" + pm.ToString(), LogEventImpl.DEBUG); } // load facts foreach (Fact fact in adapter.Facts) { Assert(fact); } if (HasLogListener) { ForceDispatchLog("Loaded " + WM.FB.Count + " Facts", LogEventImpl.DEBUG); } // finish the WM init WM.FinishInitialization(); } //end: using adapter if (HasLogListener) { ForceDispatchLog("NxBRE Inference Engine Rule Base Loading Finished", LogEventImpl.INFO); } }
private void BallThrown(QB thrower, WR reciever, FootBall footBall, Vector3 impactPos, float arcType, float power, bool isComplete) { }
public virtual T Get(T entity) { var query = QB <T> .SelectByPrimaryKey(); return(_dbContext.SqlConnection.Query <T>(query, entity).FirstOrDefault()); }
public virtual IEnumerable <T> GetAll() { var query = QB <T> .Select(); return(_dbContext.SqlConnection.Query <T>(query).ToList()); }
public virtual IEnumerable <T> AllIncluding(params Expression <Func <T, object> >[] includeProperties) { var query = QB <T> .Select(); return(_dbContext.SqlConnection.Query <T>(query, includeProperties).ToList()); }
public virtual int GetNewId() { var query = QB <T> .GetNewId(); return(_dbContext.SqlConnection.Query <int>(query).FirstOrDefault()); }