public void GivenAnOrmLiteTypedConnectionFactory_WhenUsingOrmLiteExtensionsAndGlobalProviderNotSet_ThenArgumentNullExceptionIsNotThrown()
        {
            using (var connection = factory.OpenDbConnection())
            {
                Assert.That(() =>
                {
                    connection.CreateTableIfNotExists <TestDao>();

                    var dao = new TestDao {
                        Id = 1, Thing = "Thing"
                    };

                    connection.Insert(dao);
                    connection.SingleById <TestDao>(1);

                    dao.Thing = "New Thing";

                    connection.Update(dao, d => d.Id == dao.Id);

                    connection.Delete(dao);

                    connection.DropTable <TestDao>();
                }, Throws.Nothing);
            }
        }
Ejemplo n.º 2
0
        public ExecuteResult UpdateListData(List <TestViewModel> updateList)
        {
            ExecuteResult executeResult = new ExecuteResult();
            TestDao       dao           = new TestDao();
            //entity接下來要帶入function,需一樣
            testEntities entity     = (testEntities)base.GetCurrentContext();
            List <int>   idList     = updateList.Select(m => m.id).ToList();
            List <test>  taregtList = entity.test.Where(m => idList.Contains(m.id)).ToList();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <TestViewModel, test>().EqualityComparison((odto, o) => odto.id == o.id).ForMember(dest => dest.hit_no, opts => opts.MapFrom(s => 0))
                .ForMember(dest => dest.hit_no, opts => opts.Ignore())
                .ForMember(dest => dest.get_no, opts => opts.Ignore())
                .ForMember(dest => dest.email_no, opts => opts.Ignore())
                .ForMember(dest => dest.approved, opts => opts.Ignore());
            });
            IMapper mapper = config.CreateMapper();

            //不能重新對應
            /*taregtList =*/ mapper.Map(updateList, taregtList).ToList();
            try
            {
                foreach (var item in taregtList)
                {
                    //用Dao的Update會GG
                    //改用https://dev-felix72.blogspot.com/2017/12/be-caution-about-modified-entity-state-after-automapping-when-doing-ef-updating.html
                    int count = dao.UpdateData(item, entity);
                    //資料有異動過為1,沒異動為0
                    //if (count != 1)
                    //    executeResult.Success = false;
                    //else
                    //    executeResult.Success = true;
                    //if (!executeResult.Success)
                    //{
                    //    break;
                    //}
                }
                executeResult.Success = true;
            }
            catch (Exception ex)
            {
                executeResult.Message = ex.Message;
                return(executeResult);
            }
            return(executeResult);
        }
 public TestsController()
 {
     _testDao     = new TestDao();
     _questionDao = new QuestionDao();
     _personDao   = new PersonDao();
 }
Ejemplo n.º 4
0
 private TestModel()
 {
     this._dao = new TestDao();
 }
 /// <summary>
 /// конструктор
 /// </summary>
 public TestComponent()
 {
     _testDao     = new TestDao();
     _questionDao = new QuestionDao();
     _answerDao   = new AnswerDao();
 }
 public static string Showing()
 {
     return(TestDao.Showing());
 }
Ejemplo n.º 7
0
 public PreparedPersonsTestsDataLocator()
 {
     _testDao     = new TestDao();
     _questionDao = new QuestionDao();
     _personDao   = new PersonDao();
 }