当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteConnection.Query方法代码示例

本文整理汇总了C#中System.Data.SQLite.SQLiteConnection.Query方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Query方法的具体用法?C# SQLiteConnection.Query怎么用?C# SQLiteConnection.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SQLite.SQLiteConnection的用法示例。


在下文中一共展示了SQLiteConnection.Query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestDapper

        public void TestDapper()
        {
            var dataSource = @"test.sqlite";
            SQLiteConnection.CreateFile(dataSource);
            var builder = new SQLiteConnectionStringBuilder
            {
                DataSource = dataSource,
                LegacyFormat = false,
                Version = 3,
                SyncMode = SynchronizationModes.Off,
                JournalMode = SQLiteJournalModeEnum.Wal
            };

            using (var tran = new TransactionScope(TransactionScopeOption.Required))
            using (var connection = new SQLiteConnection(builder.ToString()))
            {
                connection.Open();
                CreateSampleSchema(connection);

                try
                {
                    connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 1, Name = "Name-1" });
                    connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 2, Name = "Name-2" });
                    connection.Execute("INSERT INTO table1 VALUES (@Id, @Name)", new { Id = 3, Name = "Name-3" });

                    dynamic dynamicObj = connection.Query("SELECT id, name FROM table1 LIMIT 1").FirstOrDefault();

                    Console.WriteLine("Id: {0}", dynamicObj.id);
                    Console.WriteLine("Name: {0}", dynamicObj.name);

                    var mappingObj = connection.Query<Table1>("SELECT id, name FROM table1 LIMIT 1").FirstOrDefault();

                    Console.WriteLine("Id: {0}", mappingObj.Id);
                    Console.WriteLine("Name: {0}", mappingObj.Name);

                    dynamic results = connection.Query("SELECT id, name FROM table1");
                    foreach (dynamic item in results)
                    {
                        Console.WriteLine(item);
                    }

                    tran.Complete();
                }
                catch
                {
                }
            }
        }
开发者ID:einsof1031,项目名称:WindowsForms,代码行数:48,代码来源:DapperTest.cs

示例2: AvailableDryVans

 public IEnumerable<Inventory> AvailableDryVans()
 {
     var connection = new SQLiteConnection(dbPath);
     connection.Open();
     var DryVans = connection.Query<Inventory>("select * from inventory where status != 'major' and type == 'dry_van' and reserved == 0");
     return DryVans;
 }
开发者ID:Jusharra,项目名称:reservations-2,代码行数:7,代码来源:ReservationRepository.cs

示例3: Find

        public IToken Find(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
                return null;

            using (var connection = new SQLiteConnection(ConnectionString))
            {
                connection.Open();

                var token = connection.Query<Token>(
                    @"SELECT UserId, OrganisationId, ConsumerKey, ConsumerSecret, TokenKey, TokenSecret, ExpiresAt, Session, SessionExpiresAt
                    FROM tokens
                    WHERE UserId = @UserId",
                    new
                    {
                        userId
                    }).FirstOrDefault();

                if (null != token && token.ExpiresAt.HasValue)
                {
                    // This is done because SQLite seems to be storing it as local time.
                    token.ExpiresAt = token.ExpiresAt.Value.ToUniversalTime();
                }

                return token;
            }
        }
开发者ID:ChrisRomp,项目名称:Xero-Net,代码行数:27,代码来源:SqliteTokenStore.cs

示例4: AvailableFlatBeds

 public IEnumerable<Inventory> AvailableFlatBeds()
 {
     var connection = new SQLiteConnection(dbPath);
     connection.Open();
     var FlatBeds = connection.Query<Inventory>("select * from inventory where status != 'major' and type == 'flatbed' and reserved == 0");
     return FlatBeds;
 }
开发者ID:Jusharra,项目名称:reservations-2,代码行数:7,代码来源:ReservationRepository.cs

示例5: CustomerNames

 public IEnumerable<String> CustomerNames()
 {
     var connection = new SQLiteConnection(dbPath);
     connection.Open();
     var names = connection.Query<String>("select distinct customer_name from reservations");
     return names;
 }
开发者ID:Jusharra,项目名称:reservations-2,代码行数:7,代码来源:ReservationRepository.cs

示例6: AvailableReefers

 public IEnumerable<Inventory> AvailableReefers()
 {
     var connection = new SQLiteConnection(dbPath);
     connection.Open();
     var Reefers = connection.Query<Inventory>("select * from inventory where status != 'major' and type == 'reefer' and reserved == 0");
     return Reefers;
 }
开发者ID:Jusharra,项目名称:reservations-2,代码行数:7,代码来源:ReservationRepository.cs

示例7: AllReservations

 public IEnumerable<Inventory> AllReservations()
 {
     var connection = new SQLiteConnection(dbPath);
     connection.Open();
     var reservations = connection.Query<Inventory>("select * from inventory");
     return reservations;
 }
开发者ID:Jusharra,项目名称:reservations-2,代码行数:7,代码来源:ReservationRepository.cs

示例8: CustomerReservations

 public IEnumerable<Reservations> CustomerReservations()
 {
     var connection = new SQLiteConnection(dbPath);
     connection.Open();
     var reservationcounts = connection.Query<Reservations>("select * from reservations order by");
     return reservationcounts;
 }
开发者ID:Jusharra,项目名称:reservations-2,代码行数:7,代码来源:ReservationRepository.cs

示例9: GetDepartmentEmployees

        public ProfileViewModel GetDepartmentEmployees(string departmentName)
        {
            IEnumerable<EmployeeProfile> employees;
            using (var conn =new SQLiteConnection(ConfigurationManager.ConnectionStrings["reedDirectory"].ConnectionString))
            {
                conn.Open();

                var departmentId = conn.Query<long>("SELECT Id from Department_Lookup where Name = @name LIMIT 1", new {name = departmentName.Capitalize()});

                employees = conn.Query<EmployeeProfile>("SELECT dl.Id, dl.Name, ProfileId, FirstName, LastName, Role, Department, ImageUrl, CartoonUrl, Tags, Extension " +
                                                        " FROM employeeprofile e inner join department_lookup dl on e.department = dl.id" +
                                                        " group by dl.Id, dl.Name, ProfileId, FirstName, LastName, Role, Department, ImageUrl, Tags " +
                                                        " Having dl.Id = @departmentId ",
                                                        new { departmentId = departmentId});
            }
            return new ProfileViewModel(employees.LoadHelpers());
        }
开发者ID:reedcouk,项目名称:wiki-toons,代码行数:17,代码来源:ImplDepartmentRepository.cs

示例10: GetLogs

 public IEnumerable<Log> GetLogs(DateTime? from = null)
 {
     var date = from.HasValue ? from.Value : DateTime.MinValue;
     using (var connection = new SQLiteConnection(ConnectionString))
     {
         var logs = connection.Query<Log>("select * from Log where date > @date", date);
         return logs;
     }
 }
开发者ID:jibedoubleve,项目名称:shell,代码行数:9,代码来源:LogReader.cs

示例11: QueryCities

        private static IEnumerable<MajorCity> QueryCities(string query, object paramaters = null)
        {
            using (IDbConnection con = new SQLiteConnection("Data Source=MajorCities.db"))
            {
                con.Open();

                return con.Query<MajorCity>(query, paramaters);
            }
        }
开发者ID:roja,项目名称:MockPlaces,代码行数:9,代码来源:MajorCities.cs

示例12: LoadHelpers

        public static IEnumerable<EmployeeProfile> LoadHelpers(this IEnumerable<EmployeeProfile> profiles)
        {
            using (DbConnection conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["reedDirectory"].ConnectionString))
            {
                conn.Open();

                foreach (var profile in profiles)
                {
                  profile.ImageUrl = LoadDefaultProfileImage(profile);
                    profile.RoleLookup = conn.Query<Role_Lookup>(CreateQuery(profileRoleQuery, "@RoleId"), new { RoleId = profile.Role }).SingleOrDefault();
                    profile.SeatingFloorLookup = conn.Query<SeatingFloor_Lookup>(CreateQuery(profileFloorQuery, "@FloorId"), new { FloorId = profile.SeatingFloor }).SingleOrDefault();
                    profile.DepartmentLookup = conn.Query<Department_Lookup>(CreateQuery(profileDepartmentQuery, "@DepartmentId"), new { DepartmentId = profile.Department }).SingleOrDefault();
                }

                conn.Close();
            }

            return profiles;
        }
开发者ID:reedcouk,项目名称:wiki-toons,代码行数:19,代码来源:ExtensionMethods.cs

示例13: LoadHelper

        public static EmployeeProfile LoadHelper(this EmployeeProfile profile)
        {
            using (DbConnection conn = new SQLiteConnection(ConfigurationManager.ConnectionStrings["reedDirectory"].ConnectionString))
            {
              if (profile != null)
              {
                conn.Open();

                profile.ImageUrl = LoadDefaultProfileImage(profile);
                  profile.RoleLookup = conn.Query<Role_Lookup>(CreateQuery(profileRoleQuery, "@RoleId"), new { RoleId = profile.Role }).SingleOrDefault();

                    profile.SeatingFloorLookup = conn.Query<SeatingFloor_Lookup>(CreateQuery(profileFloorQuery, "@FloorId"), new { FloorId = profile.SeatingFloor}).SingleOrDefault();
                    profile.DepartmentLookup = conn.Query<Department_Lookup>(CreateQuery(profileDepartmentQuery, "@DepartmentId"), new { DepartmentId = profile.Department }).SingleOrDefault();
                conn.Close();
              }
            }

            return profile;
        }
开发者ID:reedcouk,项目名称:wiki-toons,代码行数:19,代码来源:ExtensionMethods.cs

示例14: GetPersons

        public HttpResponseMessage GetPersons()
        {
            var dbpath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data");
              var dbfile = dbpath + "/people.db3";

              using (var conn = new SQLiteConnection("Data Source=" + dbfile))
              {
            var people = conn.Query<Person>("select * from person");
            return Request.CreateResponse(HttpStatusCode.OK, people);
              }
        }
开发者ID:davidmdem,项目名称:sqllite-on-azure,代码行数:11,代码来源:PersonController.cs

示例15: GetGrammar

        /*
        public static Choices GetGrammar(string contextname = null)
        {
            if (String.IsNullOrEmpty(contextname))
            {
                var commands = new Choices();
                using (SQLiteConnection sqlite = new SQLiteConnection(GlobalManager.SQLCHAIN))
                {

                    List<SENTENCES> sentence = sqlite.Query<SENTENCES>("SELECT * from SENTENCES").ToList();
                    foreach (SENTENCES sen in sentence)
                    {
                        sen.CMD = sqlite.Query<COMMANDS>(String.Format("SELECT * FROM COMMANDS where COMMANDS.ID in (select CMDID from TRIGGERCMD where SENID = {0})", sen.SENID)).Single();
                        commands.Add(new SemanticResultValue(sen.SENTENCE, sen.CMD.CMD));
                    }
                }
                return commands;
            }
            return null;
        }*/
        public static Context GetContext(string ContextName = null)
        {
            SYSCONTEXT = new Context();
            using (SQLiteConnection sqlite = new SQLiteConnection(GlobalManager.SQLCHAIN))
            {
                string sql = "select * from SENTENCES INNER JOIN COMMANDS on COMMANDS.ID in (select CMDID from TRIGGERCMD where SENTENCES.SENID = TRIGGERCMD.SENID) INNER JOIN MODULES on MODULES.NAME = COMMANDS.MODULENAME";
                SYSCONTEXT.SENTENCESLIST = new List<SENTENCES>();
                SYSCONTEXT.SENTENCESLIST = sqlite.Query<SENTENCES, COMMANDS, MODULES, SENTENCES>(sql, (sentence, command, module) => { command.MODULE = module; sentence.CMD = command; return sentence; }).ToList<SENTENCES>();
            }
            return SYSCONTEXT;
        }
开发者ID:MATHIAS15,项目名称:MATHIAS-Human-Testing-,代码行数:31,代码来源:DbContext.cs


注:本文中的System.Data.SQLite.SQLiteConnection.Query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。