本文整理汇总了C#中Repository.Find方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Find方法的具体用法?C# Repository.Find怎么用?C# Repository.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.Find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: add
public static Result add(School school)
{
using (SGContext db = new SGContext())
{
try
{
var repo = new Repository<School>(db);
var sch = repo.Find(d => d.Ad == school.Ad && d.IsDeleted == false);
var schmeb = repo.Find(d => d.MebKodu == school.MebKodu && d.IsDeleted == false);
if (sch.Count() > 0)
{
result = new Result(SystemRess.Messages.hata_ayniOkulSistemdeMevcut.ToString(), SystemRess.Messages.hatali_durum.ToString());
return result;
}
else if (schmeb.Count() > 0)
{
result = new Result(SystemRess.Messages.hata_ayniMebKoduSistemdeMevcut.ToString(), SystemRess.Messages.hatali_durum.ToString());
return result;
}
repo.Add(school);
result = new Result(SystemRess.Messages.basarili_kayit.ToString(), SystemRess.Messages.basarili_durum.ToString());
return result;
}
catch (Exception)
{
result = new Result(SystemRess.Messages.hatali_kayit.ToString(), SystemRess.Messages.hatali_durum.ToString());
return result;
}
}
}
示例2: 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);
}
示例3: Main
static void Main(string[] args)
{
var context = new DataContext("Data Source=(local);Initial Catalog=GettingStarted;Integrated Security=true;", new GettingStartedMappings());
var repository = new Repository(context);
IEnumerable<Person> results = repository.Find(new FindPersonByLastNameEmbeddedSQLQuery("Liles"));
}
示例4: Integration_LogDataContext_LogResository_Log_Find_Return_Log
public void Integration_LogDataContext_LogResository_Log_Find_Return_Log()
{
Logqso.mvc.Entities.LogDataEntity.Log Log1 = null;
// context object LogDataContext matches the same name used for LogqsoData DB
using (IDataContextAsync context = new ContestqsoDataContext())
//IUnitOfWorkDataAsync and UnitOfWorkData are used in order for Dependency Injection to inject the DataDB
using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
{
bool caught = false;
IRepositoryAsync<Logqso.mvc.Entities.LogDataEntity.Log> _logRepository = new Repository<Log>(context, unitOfWork);
try
{
Log1 = _logRepository.Find(LogId);
}
catch (Exception ex)
{
TestContext.WriteLine(string.Format("Integration_LogDataContext_LogResository_Log_Find_Return_Log exception {0}",ex.Message) );
caught = true;
}
Assert.IsFalse(caught); //exception
Assert.IsNotNull(Log1);
Assert.IsInstanceOfType(Log1, typeof(Logqso.mvc.Entities.LogDataEntity.Log));
Assert.AreEqual( LogId, Log1.LogId );
Assert.IsInstanceOfType(Log1.ContestYear, typeof(DateTime));
Assert.AreEqual(1, Log1.CallsignId );
}
}
示例5: CreateUser
public static Result CreateUser(User newUser)
{
using (SGContext db = new SGContext())
{
try
{
var userRepository = new Repository<User>(db);
var user = userRepository.Find(d => d.TCKimlik == newUser.TCKimlik);
if (user.Count() < 1)
{
if (string.IsNullOrEmpty(newUser.Sifre))
{
newUser.Sifre = newUser.TCKimlik.ToString();
}
userRepository.Add(newUser);
result = new Result(SystemRess.Messages.basarili_kayit.ToString(), SystemRess.Messages.basarili_durum.ToString());
return result;
}
else
{
result = new Result(SystemRess.Messages.hata_ayniTcSistemdeMevcut.ToString(), SystemRess.Messages.hatali_durum.ToString());
return result;
}
}
catch (Exception)
{
result = new Result(SystemRess.Messages.hatali_kayit.ToString(), SystemRess.Messages.hatali_durum.ToString());
return result;
}
}
}
示例6: Login
public static User Login(Int64 tckimlikno, string password)
{
using (SGContext db = new SGContext())
{
var userRepository = new Repository<User>(db);
var us = userRepository.Find(d => d.TCKimlik == tckimlikno && d.Sifre == password);
if (us.Count() > 0)
{
User record = new User();
SG_DAL.Enums.EnumRol rol = (SG_DAL.Enums.EnumRol)(us.FirstOrDefault().Rol);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, us.FirstOrDefault().Ad + " " + us.FirstOrDefault().Soyad, DateTime.Now, DateTime.Now.AddMinutes(120), false, rol.ToString(), FormsAuthentication.FormsCookiePath);
string encTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
HttpContext.Current.Response.Cookies.Add(cookie);
HttpCookie myCookie = new HttpCookie("LoginCookie");
myCookie["tcno"] = us.FirstOrDefault().TCKimlik.ToString();
myCookie.Expires = DateTime.Now.AddDays(1d);
HttpContext.Current.Response.Cookies.Add(myCookie);
return us.FirstOrDefault();
}
else
return null;
}
}
示例7: Delete
public void Delete(string slug)
{
using (var repository = new Repository<Entry>())
{
var entry = repository.Find(slug);
repository.Delete(entry);
}
}
示例8: Find_WithCriteria_ThrowsNotImplementedException
public void Find_WithCriteria_ThrowsNotImplementedException(Mock<IUnitOfWork> unitOfWork)
{
// Given
var sut = new Repository<object>(unitOfWork.Object);
// Then
Assert.Throws<NotImplementedException>(() => sut.Find(i => true));
}
示例9: Should_return_correct_number_of_records_based_on_criteria
public void Should_return_correct_number_of_records_based_on_criteria()
{
using (var context = new RepositoryTestDataContext())
{
var repo = new Repository<Order>(context);
Assert.AreEqual(3, repo.Find(o => o.CustomerID == "VINET").Count());
}
}
示例10: Should_return_empty_enumerable_where_no_records_match_criteria
public void Should_return_empty_enumerable_where_no_records_match_criteria()
{
using (var context = new RepositoryTestDataContext())
{
var repo = new Repository<Order>(context);
CollectionAssert.IsEmpty(repo.Find(o => o.CustomerID == "NoMatch"));
}
}
示例11: Should_throw_exception_if_null_criteria_provided
public void Should_throw_exception_if_null_criteria_provided()
{
using (var context = new RepositoryTestDataContext())
{
var repo = new Repository<Order>(context);
Assert.Throws<ArgumentNullException>(() => repo.Find(null));
}
}
示例12: Simple_Map_Test
public void Simple_Map_Test()
{
UnitOfWork unitOfWork = new UnitOfWork(NHibernateHelper.SessionFactory);
Repository repo = new Repository(unitOfWork.Session);
UserProfile userProfile = repo.Find<UserProfile>(m => m.Name.Equals("brunod")).FirstOrDefault();
Assert.AreEqual("[email protected]", userProfile.Email);
unitOfWork.Rollback();
unitOfWork.Dispose();
}
示例13: TestMethod1
public void TestMethod1()
{
var context = new Repository(new AdventureWorksContext(Settings.Default.Connection));
var query = context.Find<Product>().FilterByColor("Blue");
Console.WriteLine(((DbQuery<Product>)query).ToString());
}
示例14: ShouldApplyPaging
public void ShouldApplyPaging()
{
var uri = new Uri("http://localhost/Something/To/Test?$inlinecount=allpages&$skip=1&$top=1");
var context = GetTestContext();
var repo = new Repository(context);
var odataResponse = repo.Find(new GetByOData<ExampleLeaf>(HttpUtility.ParseQueryString(uri.Query)));
odataResponse.Count.Should().Be(3);
odataResponse.Results.Should().HaveCount(1);
}
示例15: GetCostsCount
public int GetCostsCount(int costCenterId)
{
int count;
using (var context = new SoheilEdmContext())
{
var repository = new Repository<Cost>(context);
count = repository.Find(item=>item.CostCenter != null && item.CostCenter.Id == costCenterId).Count();
}
return count;
}