Exemple #1
0
        /// <summary>
        /// Retrieves the mapping that is automatically generated for the given type.
        /// </summary>
        /// <param name="type">
        /// The type whose mapping to the database is returned.
        /// </param>
        /// <returns>
        /// The mapping represents the schema of the columns of the database and contains
        /// methods to set and get properties of objects.
        /// </returns>
        public TableMapping GetMapping(Type type)
        {
            if (_mappings == null)
            {
                _mappings = new Dictionary <string, TableMapping>();
            }
            TableMapping map;

            if (!_mappings.TryGetValue(type.FullName, out map))
            {
                EntityTypeConfigration entity = EntityConfigrationList.FirstOrDefault(t => t.FullName == type.FullName);
                if (entity != null)
                {
                    map = new TableMapping(type, entity);
                }
                else
                {
                    map = new TableMapping(type);
                }

                _mappings[type.FullName] = map;
            }
            return(map);
        }
Exemple #2
0
 public TableQuery(SQLiteConnection conn)
 {
     Connection = conn;
     Table      = Connection.GetMapping(typeof(T));
 }
Exemple #3
0
 TableQuery(SQLiteConnection conn, TableMapping table)
 {
     Connection = conn;
     Table      = table;
 }
Exemple #4
0
 /// <summary>
 /// Attempts to retrieve an object with the given primary key from the table
 /// associated with the specified type. Use of this method requires that
 /// the given type have a designated PrimaryKey (using the PrimaryKeyAttribute).
 /// </summary>
 /// <param name="pk">
 /// The primary key.
 /// </param>
 /// <param name="map">
 /// The TableMapping used to identify the object type.
 /// </param>
 /// <returns>
 /// The object with the given primary key or null
 /// if the object is not found.
 /// </returns>
 public object Find(object pk, TableMapping map)
 {
     return(Query(map, map.GetByPrimaryKeySql, pk).FirstOrDefault());
 }
Exemple #5
0
        /// <summary>
        /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
        /// in the command text for each of the arguments and then executes that command.
        /// It returns each row of the result using the specified mapping. This function is
        /// only used by libraries in order to query the database via introspection. It is
        /// normally not used.
        /// </summary>
        /// <param name="map">
        /// A <see cref="TableMapping"/> to use to convert the resulting rows
        /// into objects.
        /// </param>
        /// <param name="query">
        /// The fully escaped SQL.
        /// </param>
        /// <param name="args">
        /// Arguments to substitute for the occurences of '?' in the query.
        /// </param>
        /// <returns>
        /// An enumerable with one result for each row returned by the query.
        /// The enumerator will call sqlite3_step on each call to MoveNext, so the database
        /// connection must remain open for the lifetime of the enumerator.
        /// </returns>
        public IEnumerable <object> DeferredQuery(TableMapping map, string query, params object[] args)
        {
            var cmd = CreateCommand(query, args);

            return(cmd.ExecuteDeferredQuery <object>(map));
        }
Exemple #6
0
        /// <summary>
        /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?'
        /// in the command text for each of the arguments and then executes that command.
        /// It returns each row of the result using the specified mapping. This function is
        /// only used by libraries in order to query the database via introspection. It is
        /// normally not used.
        /// </summary>
        /// <param name="map">
        /// A <see cref="TableMapping"/> to use to convert the resulting rows
        /// into objects.
        /// </param>
        /// <param name="query">
        /// The fully escaped SQL.
        /// </param>
        /// <param name="args">
        /// Arguments to substitute for the occurences of '?' in the query.
        /// </param>
        /// <returns>
        /// An enumerable with one result for each row returned by the query.
        /// </returns>
        public List <object> Query(TableMapping map, string query, params object[] args)
        {
            var cmd = CreateCommand(query, args);

            return(cmd.ExecuteQuery <object>(map));
        }
Exemple #7
0
 public List <T> ExecuteQuery <T>(TableMapping map)
 {
     return(ExecuteDeferredQuery <T>(map).ToList());
 }