private static Vendor GetProductVendor(MSSQLContext context, ProductDTO product) { if (!context.Vendors.Any(v => v.Name == product.Vendor.Name)) { var vendor = new Vendor() { Name = product.Vendor.Name }; context.Vendors.Add(vendor); return vendor; } return context.Vendors.First(v => v.Name == product.Vendor.Name); }
private static void ReplicateVendor(MySQLContext context, IQueryable<Vendor> vendors) { foreach (var vendor in vendors) { if (!context.Vendors.Any(v => v.Name == vendor.Name)) { var newVendor = new Vendor() { Name = vendor.Name }; context.Vendors.Add(newVendor); context.SaveChanges(); } } }