Exemplo n.º 1
0
        public object SelectByPrimayKey(Type objectType, PrimaryKey primaryKey, object value)
        {
            var entityName = _datastore.Entities.GetNameForType(objectType);

            var command = new SqlCeCommand
            {
                CommandText = entityName,
                CommandType = CommandType.TableDirect,
                IndexName   = primaryKey.ConstraintName,
                Connection  = _datastore.GetConnection() as SqlCeConnection,
                Transaction = _datastore.CurrentTransaction as SqlCeTransaction
            };

            try
            {
                using (var results = command.ExecuteReader())
                {
                    if (!results.Seek(DbSeekOptions.FirstEqual, value))
                    {
                        return(null);
                    }

                    results.Read();
                    var entity     = _datastore.Entities[entityName];
                    var serializer = entity.GetSerializer();
                    serializer.UseFullName = false;
                    serializer.EntityCache = _datastore.Cache;
                    return(serializer.Deserialize(results));
                }
            }
            finally
            {
                command.Dispose();
            }
        }
Exemplo n.º 2
0
        public string[] GetTableNames()
        {
            var connection = _datastore.GetConnection();

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT name FROM sqlite_master WHERE type = 'table'";
                OrmDebug.Info(command.CommandText);

                using (var reader = command.ExecuteReader())
                {
                    var names = new List <string>();
                    while (reader.Read())
                    {
                        var name = reader.GetString(0);
                        if (name == "sqlite_sequence")
                        {
                            continue;
                        }

                        names.Add(name);
                    }
                    return(names.ToArray());
                }
            }
        }