Beispiel #1
0
        public void FetchEach()
        {
            IDagentDatabase database = new DagentDatabase("SQLite");

            database.Query(@"
                    select 
                        *
                    from 
                        customers c 
                    inner join 
                        customerPurchases cp 
                    on 
                        c.customerId = cp.customerId                 
                    order by 
                        c.customerId, cp.no")
            .Each(row => { })
            .Execute();

            List <Customer> customers = database.Query <Customer>(@"
                        select 
                            *
                        from 
                            customers c 
                        inner join 
                            customerPurchases cp 
                        on 
                            c.customerId = cp.customerId                 
                        order by 
                            c.customerId, cp.no")
                                        .Unique("customerId")
                                        .Each((model, row) =>
            {
                CustomerPurchase customerPurchaseModel = new CustomerPurchase
                {
                    customerId = model.customerId,
                    no         = row.Get <int>("no"),
                    content    = row.Get <string>("content")
                };

                if (model.CustomerPurchases == null)
                {
                    model.CustomerPurchases = new List <CustomerPurchase>();
                }

                model.CustomerPurchases.Add(customerPurchaseModel);
            })
                                        .List();

            ValidList(customers);
        }
Beispiel #2
0
        public void FetchNotAutoMapping()
        {
            IDagentDatabase database = new DagentDatabase("SQLite");

            List <CustomerWithBusiness> customers = database.Query <CustomerWithBusiness>(@"
                    select 
                        *
                    from 
                        customers c 
                    inner join
                        business b
                    on
                        c.businessId = b.businessId
                    inner join 
                        customerPurchases cp 
                    on 
                        c.customerId = cp.customerId                 
                    order by 
                        c.customerId, cp.no")
                                                    .AutoMapping(false)
                                                    .Unique("customerId")
                                                    .Each((model, row) => {
                model.customerId = row.Get <int>("customerId");
                model.name       = row.Get <string>("name");

                model.Business = new Business
                {
                    BusinessId   = row.Get <int>("businessId"),
                    BusinessName = row.Get <string>("businessName")
                };

                CustomerPurchase customerPurchaseModel = new CustomerPurchase
                {
                    customerId = model.customerId,
                    no         = row.Get <int>("no"),
                    content    = row.Get <string>("content")
                };

                if (model.CustomerPurchases == null)
                {
                    model.CustomerPurchases = new List <CustomerPurchase>();
                }

                model.CustomerPurchases.Add(customerPurchaseModel);
            })
                                                    .List();

            ValidList(customers);
        }
Beispiel #3
0
        public void InsertManyData()
        {
            IDagentDatabase database = new DagentDatabase("SQLite");

            using (ITransactionScope scope = database.TransactionScope())
            {
                database.ExequteNonQuery("delete from customers", null);
                database.ExequteNonQuery("delete from customerPurchases", null);
                database.ExequteNonQuery("delete from business", null);

                int customerNo          = 10000;
                int customerPurchasesNo = 10;
                int businessNo          = 10;

                //var customerCommand = database.Command<Customer>("customers", "customerId");
                //var customerPurchaseCommand = database.Command<CustomerPurchase>("customerPurchases", "customerId", "no");
                //var businessCommand = database.Command<Business>("business", "businessId");

                int businessId = 1;
                for (int i = 1; i <= customerNo; i++)
                {
                    Customer customer = new Customer
                    {
                        customerId = i,
                        name       = "name_" + i.ToString(),
                        businessId = businessId
                    };
                    database.Command <Customer>("customers", "customerId").Insert(customer);

                    if (businessId == 10)
                    {
                        businessId = 0;
                    }
                    businessId++;


                    for (int j = 1; j <= customerPurchasesNo; j++)
                    {
                        CustomerPurchase customerPurchase = new CustomerPurchase
                        {
                            customerId = i,
                            no         = j,
                            content    = "content_" + j.ToString()
                        };
                        database.Command <CustomerPurchase>("customerPurchases", "customerId", "no").Insert(customerPurchase);
                    }
                }

                for (int i = 1; i <= businessNo; i++)
                {
                    Business business = new Business
                    {
                        BusinessId   = i,
                        BusinessName = "business_" + i.ToString()
                    };
                    database.Command <Business>("business", "businessId")
                    .Ignore(x => x.BusinessId, x => x.BusinessName)
                    .Map((row, model) =>
                    {
                        row["businessId"]   = model.BusinessId;
                        row["businessName"] = model.BusinessName;
                    })
                    .Insert(business);
                }

                scope.Complete();
            }

            FetchForOneToOne();
        }