本文整理汇总了C#中Repository.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Save方法的具体用法?C# Repository.Save怎么用?C# Repository.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
//Create all the repos I need
var repo = new Repository();
//Get some entities
var person = repo.GetById<Person>(1);
var company = repo.GetById<Company>(2);
var order = repo.GetById<Order>(3);
//Chagne and save entities
person.FirstName = "Bob";
company.CompanyName = "Bob's House of Propane and Day Old Sushi";
order.OrderTotal = 1000000;
var personId = repo.Save(person);
var companyId = repo.Save(company);
var orderId = repo.Save(order);
Console.WriteLine("Saved person, Id is {0}", personId);
Console.WriteLine("Saved company, Id is {0}", companyId);
Console.WriteLine("Saved order, Id is {0}", orderId);
Console.ReadKey();
}
示例2: GetAccountsByCustomerSomeAccountsFound
public void GetAccountsByCustomerSomeAccountsFound()
{
IAccountRepository accountRepository = new AccountRepository(NhibernateHelper.SessionFactory);
Repository repository = new Repository(NhibernateHelper.SessionFactory);
Customer thirdParty1 = new Customer { Code = "tjdsklfs", Email = "[email protected]", LastName = "roux", FirstName = "Olivier", Password = "Pass", PasswordSalt = "sss" };
Customer thirdParty2 = new Customer { Code = "topsecret", Email = "[email protected]", LastName = "roux2", FirstName = "Olivier", Password = "Pass2", PasswordSalt = "sss" };
Account account1 = new Account { Balance = 201, BalanceDate = DateTime.Now, Number = "dsf1", Iban="12354"};
Account account2 = new Account { Balance = 202, BalanceDate = DateTime.Now, Number = "dsf2", Iban="12435"};
Role role = new Role{Id=1};
thirdParty1.RelatedAccounts.Add(account1, role);
thirdParty1.RelatedAccounts.Add(account2, role);
using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
{
repository.Save(thirdParty1);
repository.Save(thirdParty2);
repository.Save(account1);
repository.Save(account2);
repository.Flush();
IList<Account> accounts = accountRepository.GetAccountsByCustomer(thirdParty1.Id);
Assert.AreEqual(2, accounts.Count);
}
}
示例3: Main
static void Main(string[] args)
{
var soapShopDb = new SoapShopDb();
var component = new Repository(soapShopDb);
// Adding some entity
component.Add(new Customer { CustomerName = "Nata", CustomerPhone = "679011198" });
component.Save();
component.Add(new SoapProduct { Tittle = "Eucalyptus", Mass = 100, Price = 25.2M });
component.Save();
// Delating some entity
var comp = soapShopDb.Set<Customer>().FirstOrDefault(i => i.CustomerName == "Nata");
component.Delete(comp);
component.Save();
// Reading some entity
var list = component.Get<Customer>();
foreach (var item in list)
{
Console.WriteLine(item.Id + " " + item.CustomerName + " " + item.CustomerPhone + "\n");
}
// Find one
var comp2 = component.Get<Customer>(3);
Console.WriteLine(comp2.CustomerName);
}
示例4: CanDeleteAd_AdExistsAndAlreadyDeleted_ReturnFalse
public void CanDeleteAd_AdExistsAndAlreadyDeleted_ReturnFalse()
{
ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
Repository repo = new Repository(sessionFactory);
AdRepository adRepo = new AdRepository(sessionFactory);
using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
{
#region test data
Province p1 = new Province
{
Label = "p1"
};
User u = new User
{
Email = "[email protected]",
Password = "hihi"
};
repo.Save<User>(u);
City c = new City
{
Label = "city",
LabelUrlPart = "city"
};
p1.AddCity(c);
Category cat = new Category
{
Label = "Informatique",
LabelUrlPart = "Informatique",
Type = AdTypeEnum.Ad
};
Ad a = new Ad
{
Title = "video game",
Body = "the best!!",
CreatedBy = u,
CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
Category = cat,
IsDeleted = true
};
c.AddAd(a);
cat.AddAd(a);
repo.Save<Province>(p1);
repo.Save<City>(c);
repo.Save<Category>(cat);
long id = repo.Save<Ad, long>(a);
repo.Flush();
#endregion
Assert.IsFalse(adRepo.CanDeleteAd(id));
}
}
示例5: SeedData
private static void SeedData(ISession session)
{
var repository = new Repository(session);
var user = repository.Save(new Account { Email = "Tom Bombadil" });
repository.Save(new Account { Email = "Bilbo Bagins" });
const string body =
@"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
repository.Save(new Post { Title = "Sample Post", Body = body, Author = user });
}
示例6: AddTest
public void AddTest()
{
IRepository<Pacient> rep = new Repository<Pacient>(path);
int i = rep.GetAll().Count();
rep.Save(new Pacient() { Id = 10, FirstName = "2", LastName = "3" });
Assert.AreEqual(i + 1, rep.GetAll().Count());
}
示例7: create_projections
public void create_projections()
{
var projection = new SimpleEventStore.Query.AnagraficaArticolo();
// Arrange
var dispatcher = new Action<object>((evt) =>
{
var dispatchedEvent = evt as AnagraficaArticoloCensita;
if(evt!=null)
{
projection.Code = dispatchedEvent.Code;
projection.Description = dispatchedEvent.Description;
}
});
var repository = new Repository(eventsDispatcher: dispatcher);
var code = "001";
var description = "SSD Crucial M4 256GB";
var item = new AnagraficaArticolo();
item.Censisci(TestConfig.Id, code, description, "NR", 100);
// Act
repository.Save(item);
// Assert
Assert.AreEqual(code, projection.Code);
Assert.AreEqual(description, projection.Description);
}
示例8: CanConvertNeighborhoodsToBorderMarkersAndInserIntoDatabase
public void CanConvertNeighborhoodsToBorderMarkersAndInserIntoDatabase()
{
Repository repository = new Repository();
int orderNumber;
int idOfNeighborhoodborderMarker = 0;
int totalRowCount = 0;
List<NeighborhoodBorderMarker> neighborhoodBorderMarkers = new List<NeighborhoodBorderMarker>();
foreach (Neighborhood neighborhood in neighborhoods)
{
orderNumber = 0;
foreach (var setOfCoordinates in neighborhood.geometry.coordinates[0])
{
neighborhoodBorderMarkers.Add(new NeighborhoodBorderMarker()
{
Id = idOfNeighborhoodborderMarker,
NeighborhoodId = neighborhood.id,
OrderId = orderNumber,
Latitude = setOfCoordinates[0],
Longitude = setOfCoordinates[1]
});
orderNumber++;
totalRowCount++;
}
idOfNeighborhoodborderMarker++;
}
repository.Save(neighborhoodBorderMarkers);
}
示例9: PackageManager
public PackageManager(Repository repo, IAbsoluteDirectoryPath workDir, bool createWhenNotExisting = false,
string remote = null) {
Contract.Requires<ArgumentNullException>(repo != null);
Contract.Requires<ArgumentNullException>(workDir != null);
WorkDir = workDir;
Repo = repo;
StatusRepo = new StatusRepo();
Settings = new PackageManagerSettings();
Repository.Factory.HandlePathRequirements(WorkDir, Repo);
if (!WorkDir.Exists) {
if (!createWhenNotExisting)
throw new Exception("Workdir doesnt exist");
WorkDir.MakeSurePathExists();
}
if (!string.IsNullOrWhiteSpace(remote)) {
var config =
Repository.DeserializeJson<RepositoryConfigDto>(
FetchString(Tools.Transfer.JoinUri(new Uri(remote), "config.json")));
if (config.Uuid == Guid.Empty)
throw new Exception("Invalid remote, does not contain an UUID");
Repo.AddRemote(config.Uuid, remote);
Repo.Save();
}
Repository.Log("Opening repository at: {0}. Working directory at: {1}", Repo.RootPath, WorkDir);
_remote = remote;
}
示例10: Delete
public void Delete()
{
using (var context = new MainContext())
{
var myRepo = new Repository<Core.Customer>(context);
TotalCustomersBeforeTestRuns = myRepo.GetAll().Count();
var allEntities = myRepo.GetAll().ToList();
if (allEntities.Count > 0)
{
//Find an entity to be removed.
var firstClientInTheDb = allEntities.FirstOrDefault();
//Check if there is an entity to be removed
if (firstClientInTheDb != null)
{
myRepo.Remove(firstClientInTheDb.Id);
myRepo.Save();
TotalOfClientsAfterTheTestRuns = myRepo.GetAll().Count();
// Check if the total number of entites was reduced by one.
Assert.AreEqual(TotalCustomersBeforeTestRuns - 1, TotalOfClientsAfterTheTestRuns);
}
}
}
}
示例11: Insert
public void Insert()
{
using (var context = new MainContext())
{
var myRepo = new Repository<Address>(context);
TotalAdresssBeforeTestRuns = myRepo.GetAll().Count();
//Have to provide a valid name and e-mail address
MyNewAddress = new Address
{
AddressLine1 = "Barão de Mesquita Street",
AddressLine2 = "Tijuca",
Country = MyCountryTest,
State = "RJ",
Zip = "20540-156"
};
myRepo.Add(MyNewAddress);
myRepo.Save();
TotalOfClientsAfterTheTestRuns = myRepo.GetAll().Count();
//Assert that the number of clients increase by 1
Assert.AreEqual(TotalAdresssBeforeTestRuns + 1, TotalOfClientsAfterTheTestRuns);
}
}
示例12: Crop
//path - file name
public ActionResult Crop(string path, int from, int to)
{
//ppath - directory
string ppath = "C:\\Users\\Administratorius\\Documents\\GitHub\\MusicEditor\\PawellsMusicEditor\\PawellsMusicEditor\\Content\\Songs\\";
string editedFile = "croped " + path;
for (int i = 0; i < 100; i++)
{
if (!System.IO.File.Exists(ppath + (i + 1) + editedFile))
{
editedFile = (i + 1) + editedFile;
WavFileUtils.TrimWavFile(ppath + path, ppath + editedFile, TimeSpan.FromSeconds(from), TimeSpan.FromSeconds(to));
break;
}
}
IRepository repository = new Repository(SessionFactoryProvider);
var soundTracks = new SoundTracks
{
SoundTrackName = editedFile
};
if (editedFile.Length < 200)
{
repository.Save(soundTracks);
}
else
{
}
return RedirectToAction("Index");
}
示例13: Should_Save_a_Job
public void Should_Save_a_Job()
{
var fixture = new Fixture();
var job = fixture.Build<Job>()
.Without(c => c.Id)
.CreateAnonymous();
using (var saveContext = DbContext())
{
var repo = new Repository<Job>(saveContext);
repo.InsertOrUpdate(job);
repo.Save();
}
Job savedJob;
using (var readContext = DbContext())
{
var repo1 = new Repository<Job>(readContext);
savedJob = repo1.Find(job.Id);
}
// savedJob.Id.ShouldEqual(1);
var compare = new KellermanSoftware.CompareNetObjects.CompareObjects();
// savedJob is a proxy
compare.MaxDifferences = 1;
compare.Compare(job, savedJob);
(compare.Differences.Count <= 1).ShouldBeTrue();
Debug.WriteLine(compare.DifferencesString);
}
示例14: About
public ActionResult About()
{
// Generiskt Repository - Här skapas ett repository för Category
// Repositoryt kräver typer som implementerar IEntity
Repository<Category> categoryRepo = new Repository<Category>();
// Samtliga metoder som finns med i det generiska repositoriet
var categories = categoryRepo.FindAll();
var filteredCategories = categoryRepo.FindAll(c => c.Name.Contains("sport"));
var category = categoryRepo.FindByID(0);
category.Name = "New Name!";
categoryRepo.Save(category);
categoryRepo.Delete(category);
ProductRepository productRepo = new ProductRepository();
var products = productRepo.FindAll(); // + övriga "grund"-metoder
// Metoder implementerade i ProductRepository:
var productsForCategory = productRepo.FindProductsByCategoryID(0);
var productsWithEmptyName = productRepo.FindAll(ProductRepository
.FilterProductsWithEmptyDescription);
return View();
}
示例15: FindIndividualCustomersByName
public void FindIndividualCustomersByName()
{
ICustomerRepository customerRepository = new CustomerRepository(NhibernateHelper.SessionFactory);
Repository repository = new Repository(NhibernateHelper.SessionFactory);
Customer customer = new Customer { Code = "tjdsklfs", Email = "[email protected]", FirstName = "Sim", LastName = "Lehericey", Password = "Toto", PasswordSalt = "sss" };
IList<Customer> customers1;
IList<Customer> customers2;
IList<Customer> customers3;
using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
{
repository.Save(customer);
//repository.Save(account1);
repository.Flush();
String[] names1 = { customer.FirstName };
String[] names2 = { customer.LastName };
String[] names3 = { customer.FirstName, customer.LastName };
customers1 = customerRepository.FindCustomersByName(names1);
customers2 = customerRepository.FindCustomersByName(names2);
customers3 = customerRepository.FindCustomersByName(names3);
Assert.IsNotNull(customers1);
Assert.IsNotNull(customers2);
Assert.IsNotNull(customers3);
}
Assert.AreEqual("[email protected]", customers1[0].Email);
Assert.AreEqual("[email protected]", customers2[0].Email);
Assert.AreEqual("[email protected]", customers3[0].Email);
}