本文整理汇总了C#中Repository.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Count方法的具体用法?C# Repository.Count怎么用?C# Repository.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.Count方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanCount
public void CanCount()
{
using (var database = new MongoDbTest())
{
var repository = new Repository<ToDoItem>(database.Database);
var item = new ToDoItem() { Item = "Item", Title = "Title" };
item = repository.Insert(item);
Assert.NotNull(item);
Assert.Equal(1, repository.Count(e => e.Title == "Title"));
Assert.Equal(0, repository.Count(e => e.Title == "test"));
}
}
示例2: ShouldFilterByGenre
public void ShouldFilterByGenre()
{
using (var session = _documentStore.OpenSession())
{
var repository = new Repository(session);
Enumerable.Range(1, 8).ToList().ForEach(i => repository.Create(new Book { Title = "Book " + i, Language = "Venda", Genre = "Poetry"}));
var book1 = new Book { Title = "Book 9", Language = "Zulu", AgeRange = "0-2", Genre = "Picture Books"};
repository.Create(book1);
var book2 = new Book { Title = "Book 10", Language = "Zulu", AgeRange = "3-5", Genre = "Fiction" };
repository.Create(book2);
session.SaveChanges();
Assert.AreEqual(10, repository.Count<Book>());
var expectedBooks = new List<Book> { book1 };
var booksController = new BooksController(repository);
var view = (ViewResult)booksController.Filter(new List<string>(), new List<string>(), new List<string> {"Picture Books"});
var filterInformation = (FilterInformation)view.Model;
var actualBooks = filterInformation.BookInformations.Select(bookInformation => bookInformation.Model).ToList();
Assert.AreEqual(1, actualBooks.Count());
Assert.AreEqual(expectedBooks.First().Language, actualBooks.First().Language);
Assert.AreEqual(expectedBooks.First().AgeRange, actualBooks.First().AgeRange);
Assert.AreEqual(expectedBooks.First().Genre, actualBooks.First().Genre);
Assert.AreEqual("Picture Books", filterInformation.Genres.First());
}
}
示例3: Find_EntityFound
public void Find_EntityFound()
{
const string entity = "etn";
_dbSet.Add(entity);
using (_mockRepository.Record())
{
_dbContext.Stub(x => x.Set<String>())
.IgnoreArguments()
.Return(_dbSet);
}
var result = new Repository<String>(_dbContext).Find(x => x == entity);
Assert.AreEqual(result.Count(), 1);
}
示例4: ShouldCountDocuments
public void ShouldCountDocuments()
{
using (var session = _documentStore.OpenSession())
{
session.Store(new StaticPage { Title = "test2", CreatedAt = DateTime.Now.AddMinutes(1) });
session.Store(new StaticPage { Title = "test", CreatedAt = DateTime.Now });
session.SaveChanges();
var repository = new Repository(session);
Assert.AreEqual(2, repository.Count<StaticPage>());
}
}
示例5: protetor_ContactSelected
async void protetor_ContactSelected (object sender, ContactPickedEventArgs e)
{
if (string.IsNullOrEmpty (e.Email)) {
await DependencyService.Get<IToastNotificator> ().Notify (ToastNotificationType.Error,
"MySafety", "O contato nao tem email", TimeSpan.FromSeconds (3));
return;
}
foreach (var pr in protetores)
if (pr.Email == e.Email) {
await DependencyService.Get<IToastNotificator> ().Notify (ToastNotificationType.Error,
"MySafety", "O contato já está cadastrado...", TimeSpan.FromSeconds (3));
return;
}
var x = new Repository<MysafetyUser> ().GetAllAsync ().Result.Where (pr => pr.Email == e.Email);
var panicProtector = new PanicContacts ();
if (x == null) {
await DependencyService.Get<IToastNotificator> ().Notify (ToastNotificationType.Error,
"Erro Consultando Servidor", "Deseja enviar continuar cadastro?", TimeSpan.FromSeconds (3));
panicProtector.Estado = 'S';
} else if (x.Count () == 0) {
//TODO terminar codigo necessario
await DependencyService.Get<IToastNotificator> ().Notify (ToastNotificationType.Error,
"Protetor nao tem MySafety", "Deseja enviar link para download do App?", TimeSpan.FromSeconds (3));
panicProtector.Estado = 'S';
//TODO panicProtector.Protector_user_Id tem que ser setado quando o protetor fizer cadastro..
} else {
panicProtector.Estado = 'C';
panicProtector.ProtUserId = x.ElementAtOrDefault (0).Id;
}
panicProtector.Id = ++nextIDProtetor + "";
panicProtector.Name = e.Name;
panicProtector.phoneNumber = e.Phone;
panicProtector.Email = e.Email;
panicProtector.SendSms = true;
panicProtector.SendEmail = true;
panicProtector.CanPanic = true;
panicProtector.CanTrack = true;
panicProtector.UserId = Settings.user_Id;
protetores.Add (panicProtector);
await PanicContactRp.CreateAsync (panicProtector);
//Apenas para testes: O meu protetor me cadastrando como seu protetor
panicProtector.Id = Extensions.Randomize ();
panicProtector.Name = Settings.nome;
panicProtector.phoneNumber = string.Empty; //seria o meu fone
panicProtector.Email = Settings.email;
panicProtector.SendSms = true;
panicProtector.SendEmail = true;
panicProtector.CanPanic = true;
panicProtector.CanTrack = true;
panicProtector.Id = panicProtector.ProtUserId;
panicProtector.ProtUserId = Settings.user_Id;
protegidos.Add (panicProtector);
await PanicContactRp.CreateAsync (panicProtector);
}
示例6: Execute
public void Execute(IJobExecutionContext context)
{
if (Singleton.Instance.SourceMountpoints == null || Singleton.Instance.SourceMountpoints.Count == 0)
{
return;
}
try
{
using (Repository repo = new Repository())
{
foreach (var sourceMount in Singleton.Instance.SourceMountpoints)
{
var construct = new DriveConstruct(sourceMount.MountPoint);
Win32Api.USN_JOURNAL_DATA newUsnState;
List<Win32Api.UsnEntry> usnEntries;
NtfsUsnJournal journal = new NtfsUsnJournal(construct.DriveLetter);
var drivePath = Path.Get(construct.DriveLetter);
logger.Trace("Polling for changes from " + sourceMount.CurrentUSNLocation);
var rtn = journal.GetUsnJournalEntries(construct.CurrentJournalData, reasonMask, out usnEntries, out newUsnState, OverrideLastUsn: sourceMount.CurrentUSNLocation);
if (rtn == NtfsUsnJournal.UsnJournalReturnCode.USN_JOURNAL_SUCCESS)
{
List<RawUSNEntry> entries = new List<RawUSNEntry>();
if (usnEntries.Any())
{
logger.Debug("USN returned with " + usnEntries.Count + " entries");
}
List<USNChangeRange> changeRange = new List<USNChangeRange>();
foreach (var frn in usnEntries.Select(e=>e.FileReferenceNumber).Distinct())
{
var entriesForFile = usnEntries.Where(f => f.FileReferenceNumber == frn).ToList();
if (entriesForFile.All(e => e.SourceInfo == Win32Api.UsnEntry.USNJournalSourceInfo.DataManagement || e.SourceInfo == Win32Api.UsnEntry.USNJournalSourceInfo.ReplicationManagement))
{
continue;
}
var actualPath = GetActualPath(journal, entriesForFile.FirstOrDefault());
if (actualPath == "Unavailable" || String.IsNullOrWhiteSpace(actualPath) )
{
continue;
}
if (sourceMount.IgnoreList != null && sourceMount.IgnoreList.Any() && sourceMount.IgnoreList.Any(ignore => new Regex(ignore).IsMatch(actualPath)))
{
continue;
}
USNChangeRange range = new USNChangeRange
{
FRN = frn,
Min = entriesForFile.Min(e => e.TimeStamp),
Max = entriesForFile.Max(e => e.TimeStamp),
Closed = entriesForFile.OrderBy(f => f.TimeStamp).LastOrDefault() != null ? (entriesForFile.OrderBy(f => f.TimeStamp).LastOrDefault().Reason & Win32Api.USN_REASON_CLOSE) != 0 : false,
RenameFrom = entriesForFile.FirstOrDefault(e => (e.Reason & Win32Api.USN_REASON_RENAME_OLD_NAME) != 0),
Entry = entriesForFile.OrderBy(f => f.TimeStamp).LastOrDefault()
};
changeRange.Add(range);
}
//logger.Trace("ChangeRange : " + changeRange.Count);
foreach (var item in changeRange)
{
var actualPath = GetActualPath(journal, item.Entry as Win32Api.UsnEntry );
if (actualPath == "Unavailable")
{
continue;
}
string relativePath;
try
{
Uri drivePathUri = new Uri(drivePath.FullPath, UriKind.Absolute);
Uri actualPathUri = new Uri(actualPath, UriKind.Absolute);
relativePath = Uri.UnescapeDataString(drivePathUri.MakeRelativeUri(actualPathUri).ToString());
}
catch (Exception e)
{
relativePath = "#ERROR#";
}
if (relativePath == "#ERROR#" || relativePath.StartsWith("System Volume Information"))
{
continue;
//.........这里部分代码省略.........
示例7: Find_EntityNotFound
public void Find_EntityNotFound()
{
using (_mockRepository.Record())
{
_dbContext.Stub(x => x.Set<String>())
.IgnoreArguments()
.Return(_dbSet);
}
var result = new Repository<String>(_dbContext).Find(x => x == "temp");
Assert.AreEqual(result.Count(), 0);
}
示例8: Table_SetIsEmpty
public void Table_SetIsEmpty()
{
using (_mockRepository.Record())
{
_dbContext.Stub(x => x.Set<String>())
.IgnoreArguments()
.Return(_dbSet);
}
var result = new Repository<String>(_dbContext).Table;
Assert.IsNotNull(result);
Assert.AreEqual(result.Count(), 0);
}