コード例 #1
0
ファイル: SqlDataStore.cs プロジェクト: 403016605/CQRS
        public SqlDataStore(IConfigurationManager configurationManager, ILogger logger)
        {
            ConfigurationManager = configurationManager;
            Logger = logger;
            // Use a connection string.
            DbDataContext = CreateDbDataContext();

            // Get a typed table to run queries.
            Table = DbDataContext.GetTable <TData>();
        }
コード例 #2
0
        /// <summary>
        /// Instantiates a new instance of the <see cref="LinqToSqlDataStore{TData}"/> class
        /// </summary>
        public LinqToSqlDataStore(IConfigurationManager configurationManager, ILogger logger)
        {
            ConfigurationManager = configurationManager;
            Logger = logger;
            // ReSharper disable DoNotCallOverridableMethodsInConstructor
            DbDataContext = CreateDbDataContext();
            WriteableConnectionStrings = GetWriteableConnectionStrings();
            // ReSharper restore DoNotCallOverridableMethodsInConstructor

            // Get a typed table to run queries.
            Table = DbDataContext.GetTable <TData>();
        }
コード例 #3
0
        private void readToolStripMenuItem_Click(object sender, EventArgs e)
        {
            connlayer = new ConnectedLayer();
            dc        = new DbDataContext <Airplane>(connlayer.connectionString);
            Airplane airplane = new Airplane();

            var query = from u in dc.GetTable <Airplane>()
                        where u.Id > 5
                        select u;

            dataGridView1.DataSource = query.ToList();
            dc.SubmitChanges();
        }
コード例 #4
0
        private void procedureToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            dc = new DbDataContext <Airplane>(connlayer.connectionString);

            int id1 = (int)dataGridView1.CurrentCell.Value;

            var air = dc.GetTable <Airplane>();
            int _id = dc.GetAgeRange(ref id1);

            var query = from i in air
                        where i.Id == _id
                        select i;

            foreach (Airplane airplane in query)
            {
                dataGridView1.DataSource = query;
            }
        }
コード例 #5
0
ファイル: Test_DB_Consts.cs プロジェクト: raedayyad/sharp-sms
 public void SellChannels()
 {
     using (var db = new DbDataContext()) {
         // Проверяем наличие в enum всех значений из таблицы в БД
         Table <SellChannel> table = db.GetTable <SellChannel>();
         foreach (SellChannel x in table)
         {
             CheckValue <SellChannelEnum>(x.name, x.id);
         }
         // Выбираем все значения из enum'а и ищем их в БД, если такого нет => рекомендуем удалить поле
         foreach (FieldInfo field in typeof(SellChannelEnum).GetFields())
         {
             SellChannel channel = table.SingleOrDefault(t => t.name == field.Name);
             if (field.Name == "value__")
             {
                 continue;
             }
             Assert.IsNotNull(channel, "Удалите " + field.Name + " - его нет в БД");
             Assert.AreEqual(channel.name, field.Name, "Удалите " + field.Name + " - имя в БД другое");
         }
     }
 }
コード例 #6
0
ファイル: HomeController.cs プロジェクト: omersahinn/apcurs
        public ActionResult index()
        {
            QuestionAndArticleModel model  = new QuestionAndArticleModel();
            QuestionModel           qmodel = new QuestionModel();
            ArticleModel            amodel = new ArticleModel();
            Tag        t  = new Tag();
            List <Tag> lt = new List <Tag>();

            var temp = (from q in db.GetTable <Question>()
                        select new QuestionModel()
            {
                id = q.id,
                user = q.User,
                questionText = q.QuestionText,
                createdDate = q.CreatedDate,
                isReply = q.IsReply,
                viewCount = q.ViewCount,
                voteCount = q.VoteCount,
                shortTitle = q.ShortTitle,
                status = q.Status
            }).Where(a => a.status == true).ToList();



            foreach (var item in temp)
            {
                var ansTemp = (from q in db.GetTable <Answer>()
                               select new AnswerModel()
                {
                    id = q.id,
                    User = q.User,
                    AnswerText = q.AnswerText,
                    CreatedDate = q.CreatedDate,
                    IsSolved = q.IsSolved,
                    VoteCount = q.VoteCount,
                    Question = q.Question,
                    Status = q.Status,
                    VotedAnswers = q.VotedAnswers.ToList()
                }).Where(x => x.Status == true && x.Question.id == item.id).ToList();
                lt.Clear();

                item.answers = ansTemp;

                var a = db.QuestionTags.Where(z => z.QuestionId == item.id).Select(x => new { x.TagId }).ToList();
                if (a != null)
                {
                    foreach (var item1 in a)
                    {
                        t = db.Tags.Where(q => q.id == item1.TagId).FirstOrDefault();
                        lt.Add(t);
                    }
                    item.tags = lt.ToList();
                }
            }
            var asd = temp;



            var temp2 = (from q in db.Articles.ToList()
                         select new ArticleModel
            {
                id = q.id,
                user = q.User,
                articleText = q.ArticleText,
                createdDate = q.CreatedDate,
                viewCount = q.ViewCount,
                likeCount = q.LikeCount,
                shortTitle = q.ShortTitle,
                articlePicture = q.ArticlePicture,
                status = q.Status
            }).Where(a => a.status == true).ToList();

            foreach (var item2 in temp2)
            {
                item2.comment = db.ArticleComments.Where(a => a.Articleid == item2.id).ToList();
            }


            var Lastquestion        = temp.OrderByDescending(a => a.createdDate).Take(20);
            var NotAnsweredQuestion = temp.Where(c => c.answers.Count == 0).OrderByDescending(a => a.createdDate).Take(20);
            var Viewedanswer        = temp.OrderByDescending(a => a.viewCount).Take(20);
            var answeredQuestion    = temp.OrderByDescending(a => a.answers.Count()).Take(20);

            var Lastarticle   = temp2.OrderByDescending(a => a.createdDate).Take(10);
            var Likedarticle  = temp2.OrderByDescending(a => a.likeCount).Take(20);
            var Viewedarticle = temp2.OrderByDescending(a => a.viewCount).Take(20);



            model.lastQuestions        = Lastquestion;
            model.notAnsweredQuestion  = NotAnsweredQuestion;
            model.mostViewedQuestion   = Viewedanswer;
            model.mostAnsweredQuestion = answeredQuestion;

            model.lastArticles       = Lastarticle;
            model.mostLikedArticles  = Likedarticle;
            model.mostViewedArticles = Viewedarticle;


            var items = (from ar in db.ArticleComments.ToList()
                         select new CommentModel
            {
                id = ar.id,
                User = ar.User,
                Article = ar.Article,
                CreatedDate = ar.CreatedDate,
                CommentText = ar.CommentText,
                Status = ar.Status
            }).Where(a => a.Status == true).OrderByDescending(a => a.CreatedDate).ToList();

            //var catItems = (from s in db.Categories.ToList()
            //                select new CategoryModel
            //                {
            //                    id = s.id,
            //                    Count = s.Articles.Count(),
            //                    CategoryName = s.CategoryName,
            //                    SubCategory = s.SubCategories.ToList(),
            //                    Status = s.Status
            //                }).Where(a => a.Status == true).ToList();
            //ViewBag.categories = catItems;
            ViewBag.comments = items;
            return(View(model));
        }