示例#1
0
 //[Test]
 public void SelectAllTitlesFull2()
 {
     using (var db = new MusicDB())
     {
         var query2 = new FullSqlQuery(db);
         var titles = query2.SelectAll<Title>();
         var title  = (Title) query2.SelectByKey(typeof (Title), 137653);
     }
 }
示例#2
0
        //[Test]
        public void SelectAllArtistsIgnoreLazyLoading()
        {
            using (var db = new MusicDB())
            {
                var query2  = new FullSqlQuery(db, true); //loading is automatic
                var artist2 = (Artist2) query2.SelectByKey(typeof (Artist2), 2643);
                var titles2 = artist2.Titles;

                var query  = new FullSqlQuery(db); // Dont ignore lazyloading
                var artist = (Artist2) query.SelectByKey(typeof (Artist2), 2643);
                var titles = artist.Titles;
                Assert.AreEqual(titles2.Count, titles.Count);
            }
        }
        private object LoadLazy(IMapper mapper, object proxy, Type parentType)
        {
            var lazyMapper = (ILazyMapper) mapper;
            object key = lazyMapper.ParentKeyGetter(proxy);

            var fullSqlQuery = new FullSqlQuery(_db, true);
            object parentLoadFull = fullSqlQuery.SelectByKey(parentType, key);
            if (parentLoadFull == null)
            {
                object value = Activator.CreateInstance(mapper is CollectionFullObjectMapper
                                                            ? (mapper as CollectionFullObjectMapper).PropertyCollectionType
                                                            : mapper.PropertyType);
                return value;
            }

            var objectMapper = (IObjectMapper) mapper;
            return objectMapper.Getter(parentLoadFull);
        }
        public void SelectTitleWithArtistQueryAssociation()
        {
            using (var db = new MusicDB())
            {
                var query = new FullSqlQuery(db);
                var title = (Title) query.SelectByKey(typeof (Title), 137653);
                Console.WriteLine(title.Name);

                var query2 = new FullSqlQueryT<Title>(db);
                var title2 = query2.SelectByKey(137653);
                Console.WriteLine(title2.Name);
            }
        }
        public void SelectAllArtistsIgnoreLazyLoading()
        {
            using (var db = new MusicDB())
            {
                var queryI = from a in db.GetTable<Artist>()
                             where a.Id == 2471
                             select a;

                var aaa = queryI.First();
                aaa.Name = "JE NE SUIS PAS UN HÉROS";


                var data = new byte[] {0x4A, 0x45, 0x20, 0x4E, 0x45, 0x20, 0x53, 0x55, 0x49, 0x53, 0x20, 0x50, 0x41, 0x53, 0x20, 0x55, 0x4E, 0x20, 0x48, 0xC3, 0x83, 0xC2, 0x89, 0x52, 0x4F, 0x53};
                aaa.Name = Encoding.UTF8.GetString(data);

                var updateQuery = new SqlQuery(db);
                updateQuery.Update(aaa);

                var ccc = aaa.Id;

                var query2 = new FullSqlQuery(db, true); //loading is automatic
                var artist2 = (Artist2) query2.SelectByKey(typeof (Artist2), 2643);
                List<Title> titles2 = artist2.Titles;

                var query = new FullSqlQuery(db);
                var artist = (Artist2) query.SelectByKey(typeof (Artist2), 2643);
                List<Title> titles = artist.Titles;
                Assert.AreEqual(titles2.Count, titles.Count);
            }
        }