/* Copyright (C) 2008 - 2011 Jordan Marr This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ using System; using System.Data; using System.Data.Common; using System.Collections.Generic; using Marr.Data.Parameters; using System.Linq.Expressions; using Marr.Data.QGen; namespace Marr.Data { public interface IDataMapper : IDisposable { #region - Contructor, Members - string ConnectionString { get; } DbProviderFactory ProviderFactory { get; } DbCommand Command { get; } /// /// Gets or sets a value that determines whether the DataMapper will /// use a stored procedure or a sql text command to access /// the database. The default is stored procedure. /// SqlModes SqlMode { get; set; } #endregion #region - Update - UpdateQueryBuilder Update(); int Update(T entity, Expression> filter); int Update(string tableName, T entity, Expression> filter); int Update(T entity, string sql); #endregion #region - Insert - /// /// Creates an InsertQueryBuilder that allows you to build an insert statement. /// This method gives you the flexibility to manually configure all options of your insert statement. /// Note: You must manually call the Execute() chaining method to run the query. /// InsertQueryBuilder Insert(); /// /// Generates and executes an insert query for the given entity. /// This overload will automatically run an identity query if you have mapped an auto-incrementing column, /// and if an identity query has been implemented for your current database dialect. /// object Insert(T entity); /// /// Generates and executes an insert query for the given entity. /// This overload will automatically run an identity query if you have mapped an auto-incrementing column, /// and if an identity query has been implemented for your current database dialect. /// object Insert(string tableName, T entity); /// /// Executes an insert query for the given entity using the given sql insert statement. /// This overload will automatically run an identity query if you have mapped an auto-incrementing column, /// and if an identity query has been implemented for your current database dialect. /// object Insert(T entity, string sql); #endregion #region - Delete - int Delete(Expression> filter); int Delete(string tableName, Expression> filter); #endregion #region - Connections / Transactions - void BeginTransaction(IsolationLevel isolationLevel); void RollBack(); void Commit(); event EventHandler OpeningConnection; #endregion #region - ExecuteScalar, ExecuteNonQuery, ExecuteReader - /// /// Executes a non query that returns an integer. /// /// The SQL command to execute. /// An integer value int ExecuteNonQuery(string sql); /// /// Executes a stored procedure that returns a scalar value. /// /// The SQL command to execute. /// A scalar value object ExecuteScalar(string sql); /// /// Executes a DataReader that can be controlled using a Func delegate. /// (Note that reader.Read() will be called automatically). /// /// The type that will be return in the result set. /// The sql statement that will be executed. /// The function that will build the the TResult set. /// An IEnumerable of TResult. IEnumerable ExecuteReader(string sql, Func func); /// /// Executes a DataReader that can be controlled using an Action delegate. /// /// The sql statement that will be executed. /// The delegate that will work with the result set. void ExecuteReader(string sql, Action action); #endregion #region - DataSets - DataSet GetDataSet(string sql); DataSet GetDataSet(string sql, DataSet ds, string tableName); DataTable GetDataTable(string sql, DataTable dt, string tableName); DataTable GetDataTable(string sql); int InsertDataTable(DataTable table, string insertSP); int InsertDataTable(DataTable table, string insertSP, UpdateRowSource updateRowSource); int UpdateDataSet(DataSet ds, string updateSP); int DeleteDataTable(DataTable dt, string deleteSP); #endregion #region - Parameters - DbParameterCollection Parameters { get; } ParameterChainMethods AddParameter(string name, object value); IDbDataParameter AddParameter(IDbDataParameter parameter); #endregion #region - Find - /// /// Returns an entity of type T. /// /// The type of entity that is to be instantiated and loaded with values. /// The SQL command to execute. /// An instantiated and loaded entity of type T. T Find(string sql); /// /// Returns an entity of type T. /// /// The type of entity that is to be instantiated and loaded with values. /// The SQL command to execute. /// A previously instantiated entity that will be loaded with values. /// An instantiated and loaded entity of type T. T Find(string sql, T ent); #endregion #region - Query - /// /// Creates a QueryBuilder that allows you to build a query. /// /// The type of object that will be queried. /// Returns a QueryBuilder of T. QueryBuilder Query(); /// /// Returns the results of a query. /// Uses a List of type T to return the data. /// /// The type of object that will be queried. /// Returns a list of the specified type. List Query(string sql); /// /// Returns the results of a query or a stored procedure. /// /// The type of object that will be queried. /// The sql query or stored procedure name to run. /// A previously instantiated list to populate. /// Returns a list of the specified type. ICollection Query(string sql, ICollection entityList); #endregion #region - Query to Graph - /// /// Runs a query and then tries to instantiate the entire object graph with entites. /// List QueryToGraph(string sql); /// /// Runs a query and then tries to instantiate the entire object graph with entites. /// ICollection QueryToGraph(string sql, ICollection entityList); #endregion } }