Beispiel #1
0
 public void StartUp()
 {
     using (ShipmentContext context = new ShipmentContext())
     {
         context.Database.CreateIfNotExists();
     }
 }
Beispiel #2
0
 public static void Init(IServiceProvider serviceProvider)
 {
     using (var context = new ShipmentContext(
                serviceProvider.GetRequiredService <
                    DbContextOptions <ShipmentContext> >()))
     {
         context.Database.EnsureCreated();
         AddMockData(context);
     }
 }
Beispiel #3
0
        private List <object> WalkObject(Object Input, ShipmentContext context, SqlCeResultSet resultSet)
        {
            bool firstOccurrence;

            gen.GetId(Input, out firstOccurrence);
            if (!firstOccurrence)
            {
                return(null);
            }

            CachedTableInfo metadata = new CachedTableInfo(Input.GetType().Name, context, resultSet);

            List <string>        processedFields = new List <string>();
            List <object>        keys            = new List <object>();
            SqlCeUpdatableRecord r = resultSet.CreateRecord();

            // Match the database with memory object.
            for (int i = 0; i < resultSet.FieldCount; i++)
            {
                if (!metadata.IsFieldKey(r.GetName(i)))
                {
                    string       fieldName = resultSet.GetName(i);
                    PropertyInfo fi        = Input.GetType().GetProperty(fieldName);
                    if (fi != null)
                    {
                        r[i] = fi.GetValue(Input, null);
                        processedFields.Add(fieldName);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Field {0} was not found in the class {1}",
                                                                          fi.Name, Input.GetType().Name));
                    }
                }
            }
            resultSet.Insert(r, DbInsertOptions.PositionOnInsertedRow);
            foreach (var item in metadata.Keys)
            {
                keys.Add(r[item.Name]);
            }

            // keys now contain assigned autoincrement fields.
            return(keys);
        }
Beispiel #4
0
        public static void AddMockData(ShipmentContext context)
        {
            if (context.Shipments.Any())
            {
                return;   // DB has been seeded.
            }

            var shipment = new Shipment()
            {
                Orders       = GenerateOrders(),
                DeliveryDate = DateTime.Now.AddDays(20),
                Departure    = "Abisko",
                Destination  = "Greenland",
                ShipmentDate = DateTime.Now,
            };

            context.Shipments.Add(shipment);

            var shipment2 = new Shipment()
            {
                Orders       = GenerateOrders(),
                DeliveryDate = DateTime.Now.AddDays(20),
                Departure    = "Bremen",
                Destination  = "New York",
                ShipmentDate = DateTime.Now,
            };

            context.Shipments.Add(shipment2);

            var shipment3 = new Shipment()
            {
                Orders       = GenerateOrders(),
                DeliveryDate = DateTime.Now.AddDays(5),
                Departure    = "Copenhagen",
                Destination  = "London",
                ShipmentDate = DateTime.Now,
            };

            context.Shipments.Add(shipment3);

            context.SaveChanges();
        }
Beispiel #5
0
        public void Walk_Simple_Object()
        {
            Shipment shipment = GetTestShipment();

            using (SqlCeConnection conn = new SqlCeConnection(@"Data Source=c:\temp\shipments.sdf"))
                using (ShipmentContext c = new ShipmentContext())
                {
                    conn.Open();
                    using (SqlCeCommand cmd = new SqlCeCommand("Shipments", conn))
                    {
                        cmd.CommandType = System.Data.CommandType.TableDirect;

                        using (SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable))
                        {
                            List <object> keys = WalkObject(shipment, c, rs);
                        }
                    }

                    c.Shipments.Any(t => t.Description == "test shipment").Should().Be(true);
                }
        }
 public UnitOfWork(ShipmentContext shipmentContext)
 {
     this._shipmentContext = shipmentContext;
 }
 public AddressesController(ShipmentContext context)
 {
     _context = context;
 }
 public DetailsController(ShipmentContext context)
 {
     _context = context;
 }
 public ShipmentService(ShipmentContext dbContext)
 {
     _dbContext = dbContext;
 }
Beispiel #10
0
 public ContainersController(ShipmentContext context)
 {
     _context = context;
 }
 public RoutesController(ShipmentContext context)
 {
     _context = context;
 }
Beispiel #12
0
 public DriverRepository(ShipmentContext shipmentContext) : base(shipmentContext)
 {
 }
Beispiel #13
0
 public ShipmentsController(ShipmentContext context)
 {
     _context = context;
 }
Beispiel #14
0
 public CachedTableInfo(string Table, ShipmentContext context, SqlCeResultSet data)
 {
     _table   = Table;
     _context = context;
     _data    = data;
 }
Beispiel #15
0
 public BaseRepository(ShipmentContext _shipmentContext)
 {
     shipmentContext = _shipmentContext;
     this.dbSet      = shipmentContext.Set <T>();
 }
 public MessagesController(ShipmentContext context)
 {
     _context = context;
 }