本文整理汇总了C#中GenericRepository类的典型用法代码示例。如果您正苦于以下问题:C# GenericRepository类的具体用法?C# GenericRepository怎么用?C# GenericRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericRepository类属于命名空间,在下文中一共展示了GenericRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTaxToGirl
private static void AddTaxToGirl(string firstname, string lastname, int tax)
{
var girlRepo = new GenericRepository<Girl>(new GirlsAgencyContext());
var girl = girlRepo.Search(g => g.FirstName == firstname && g.LastName == lastname).FirstOrDefault();
if (girl == null)
{
throw new ApplicationException("Girl does not exists/found");
}
var girlTaxes = new GirlsTaxesEntities();
string girlFullName = girl.FirstName + " " + girl.LastName;
var girlTax = GetAssignTax(girlFullName, girlTaxes);
if (girlTax == null)
{
girlTaxes.GirlsTaxes.Add(new GirlsTax
{
GirlName = girlFullName,
Tax = tax
});
}
else
{
girlTax.Tax = tax;
}
girlTaxes.SaveChanges();
}
示例2: Get
public ICollection<Test> Get()
{
var db = new StudentSystemDbContext();
var testsRepo = new GenericRepository<Test>(db);
List<Test> tests = testsRepo.All().ToList();
return tests;
}
示例3: TestCreateBusiness
public void TestCreateBusiness()
{
var a = EntityHelper.GetAccount("first", "lastName");
var b = EntityHelper.GetBusiness("business1", Category.ActiveLife);
using (var Scope = new SQLiteDatabaseScope<PraLoupAutoMappingConfiguration>())
{
using (ISession Session = Scope.OpenSession())
{
Session.Transaction.Begin();
IRepository r = new GenericRepository(Session);
EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator());
IDataService ds = new DataService(null, bds, null, null, null, null, null, null, null, new UnitOfWork(Session));
BusinessActions ba = new BusinessActions(a, ds, new PraLoup.Infrastructure.Logging.Log4NetLogger(), null);
ba.CreateBusiness(b, a, Role.BusinessAdmin);
Session.Transaction.Commit();
}
using (ISession Session = Scope.OpenSession())
{
IRepository r = new GenericRepository(Session);
EntityDataService<Business, BusinessValidator> bds = new EntityDataService<Business, BusinessValidator>(r, new BusinessValidator());
var b1 = bds.Find(b.Id);
Assert.IsNotNull(b1);
Assert.AreEqual(b, b1);
}
}
}
示例4: Get
public ICollection<Course> Get()
{
var db = new StudentSystemDbContext();
var coursesRepo = new GenericRepository<Course>(db);
List<Course> courses = coursesRepo.All().ToList();
return courses;
}
示例5: Get
public ICollection<Student> Get()
{
var db = new StudentSystemDbContext();
var studentsRepo = new GenericRepository<Student>(db);
List<Student> students = studentsRepo.All().ToList();
return students;
}
示例6: Post
public IHttpActionResult Post(TestRequestModel model)
{
if (model == null)
{
return this.BadRequest();
}
var db = new StudentSystemDbContext();
var testsRepo = new GenericRepository<Test>(db);
var coursesRepo = new GenericRepository<Course>(db);
List<Course> allCourses = coursesRepo.All().ToList();
var testCourse = new Course
{
Name = model.Course.Name,
Description = model.Course.Description
};
var testToAdd = new Test
{
Course = testCourse
};
testsRepo.Add(testToAdd);
testsRepo.SaveChanges();
return this.Ok();
}
示例7: Constructor_If_Passed_Context_Is_Null_Must_Throw_Exception
public void Constructor_If_Passed_Context_Is_Null_Must_Throw_Exception()
{
//
// Arrange, Act, Assert
//
var repository = new GenericRepository<IModel>(null);
}
示例8: Index
//
// GET: /School/
public ActionResult Index()
{
var schoolRepository = new GenericRepository(new SchoolContext());
var students = schoolRepository.GetQuery<Student>();
return View();
}
示例9: DeleteMovieWhenExistingItemShouldDelete
public void DeleteMovieWhenExistingItemShouldDelete()
{
//Arrange -> prepare the objects
var repo = new GenericRepository<Movie>(new MoviesGalleryContext());
var movie = new Movie()
{
Id = 1,
Length = 10,
Ration = 10
};
//Act -> perform some logic
repo.Add(movie);
repo.SaveChanges();
var movieFromDb = repo.GetById(movie.Id);
repo.Delete(movieFromDb);
repo.SaveChanges();
var newMovieFromDb = repo.GetById(movie.Id);
//Asssert -> expect and exception
Assert.IsNull(newMovieFromDb);
}
示例10: Add
public object Add(AddTripModel model)
{
GenericRepository<Trip> TripRepo = new GenericRepository<Trip>();
GenericRepository<User> userRepo = new GenericRepository<User>();
User user = userRepo.GetSingle(u => u.Username == User.Identity.Name);
DateTime departDate;
if (!DateTime.TryParse(model.Depdate, out departDate))
{
return false;
}
Trip Trip = new Trip()
{
UserId =user.UserId,
DepartDate = departDate,
AvailableSeatNumber = model.Seatnum,
Price = model.Price,
DepMin=model.Min,
DepHour=model.Hour,
EstimatedHour=model.EstHour,
EstimatedMin=model.EstMin,
DepartLocationId=model.DepLocId,
ArrivalLocationId=model.ArrLocId,
CarId = 1,
};
TripRepo.Add(Trip);
return true;
}
示例11: GetUserById
public User GetUserById(int IdUser)
{
using (var repository = new GenericRepository())
{
return repository.ReadById<User>(IdUser);
}
}
示例12: Main
static void Main(string[] args)
{
var contactsRepository = new GenericRepository<Contact>();
contactsRepository.Delete(5);
//for (int i = 0; i < 1000; i++)
//{
// var currentContact = new Contact();
// currentContact.FirstName = "ContactFirstName" + i;
// currentContact.LastName = "ContactLastName" + i;
// if (i % 3 == 0)
// {
// currentContact.Sex = Sex.Male;
// currentContact.Status = Status.Active;
// }
// else if (i % 3 == 1)
// {
// currentContact.Sex = Sex.Female;
// currentContact.Status = Status.Inactive;
// }
// else
// {
// currentContact.Sex = Sex.Other;
// currentContact.Status = Status.Deleted;
// }
// Random rand = new Random();
// currentContact.Telephone = rand.Next(1000000000, 2000000000).ToString();
// contactsRepository.Add(currentContact);
//}
}
示例13: GetData
public void GetData()
{
GenericRepository<t_loan_lead> loan = new GenericRepository<t_loan_lead>(new sherlockEntities());
loan.GetAll();
GenericRepository<t_life_lead> life = new GenericRepository<t_life_lead>(new sherlockEntities());
life.GetAll();
GenericRepository<t_asu_lead> asu = new GenericRepository<t_asu_lead>(new sherlockEntities());
asu.GetAll();
GenericRepository<t_debt_lead> debt = new GenericRepository<t_debt_lead>(new sherlockEntities());
debt.GetAll();
GenericRepository<t_equityrelease_lead> equityrelease = new GenericRepository<t_equityrelease_lead>(new sherlockEntities());
equityrelease.GetAll();
GenericRepository<t_logbookloan_lead> logbookloan = new GenericRepository<t_logbookloan_lead>(new sherlockEntities());
logbookloan.GetAll();
GenericRepository<t_mortgage_lead> mortgage = new GenericRepository<t_mortgage_lead>(new sherlockEntities());
mortgage.GetAll();
GenericRepository<t_pmi_lead> pmi = new GenericRepository<t_pmi_lead>(new sherlockEntities());
pmi.GetAll();
GenericRepository<t_ppi_lead> ppi = new GenericRepository<t_ppi_lead>(new sherlockEntities());
ppi.GetAll();
GenericRepository<t_sme_mi_lead> sme_mi = new GenericRepository<t_sme_mi_lead>(new sherlockEntities());
sme_mi.GetAll();
GenericRepository<t_solar_lead> solar = new GenericRepository<t_solar_lead>(new sherlockEntities());
solar.GetAll();
}
示例14: Delete
public void Delete()
{
IGenericRepository<SysUser> user = new GenericRepository<SysUser>();
//user.Delete(4);
if (user.Submit() == -1)
Assert.Fail();
}
示例15: Main
static void Main(string[] args)
{
var loadFile = File.ReadAllLines(@"c:\users\luiz.araujo\documents\visual studio 2015\Projects\FinancialDic\FinancialDic.Load\load.csv");
_repository = new GenericRepository<Word>();
var count = 0;
foreach (var line in loadFile)
{
var words = line.Split(';');
count ++;
var word = new Word()
{
Id = count,
Portuguese = words[0],
English = words[1]
};
_repository.AddOrUpdate(word);
}
Console.WriteLine("Fim");
}