本文整理汇总了C#中Repository.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Get方法的具体用法?C# Repository.Get怎么用?C# Repository.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Get_EmptyRepository_ReturnsCorrectResult
public void Get_EmptyRepository_ReturnsCorrectResult()
{
var course = new Course("Java basics");
var course2= new Course("C Sharp advanced");
var repository = new Repository<Course>();
repository.Add(course);
repository.Add(course2);
var result = repository.Get(1);
var result2 = repository.Get(2);
Assert.AreEqual(course, result);
Assert.AreEqual(course2, result2);
}
示例3: TestGetWhitEmptyRepository
public void TestGetWhitEmptyRepository()
{
int expectedResult = default(int);
Repository<int> repository = new Repository<int>();
var actualResult = repository.Get(0);
Assert.AreEqual(expectedResult, actualResult);
}
示例4: Insert
public void Insert( )
{
muscle_log.framework.Models.MuscleLogContext ctx = new muscle_log.framework.Models.MuscleLogContext("metadata=res://*/Models.MuscleLogModel.csdl|res://*/Models.MuscleLogModel.ssdl|res://*/Models.MuscleLogModel.msl;provider=System.Data.SqlClient;provider connection string='data source=MAX-PC;Initial Catalog=muscle-log;User ID=Max-PC;integrated security=SSPI;multipleactiveresultsets=True;application name=EntityFramework'");
var unitOfWork = new EFContextUnitOfWork(ctx);
var repo = new Repository<ml_ForumThread>(unitOfWork);
ForumThreadService service = new ForumThreadService(repo);
int countBefore = service.ListThreads(muscle_log.framework.Util.Enum.Forums.Meta).Count();
ForumThreadViewModel input = new ForumThreadViewModel( );
input.ID = -1;
input.UserID = 7;
input.Title = "Testeintrag";
input.Body = "Das ist ein Testeintrag. ~*</fsd !§$(%)=&??``´´'<<<><>>>@fsdf%%<%=fds";
input.Forum = muscle_log.framework.Util.Enum.Forums.Meta;
service.Save( input );
int countAfter = service.ListThreads(muscle_log.framework.Util.Enum.Forums.Meta).Count();
// there must be one more thread than before
Assert.AreEqual( countAfter, ( countBefore + 1 ) );
// the id of the new thread must be bigger than 0
Assert.Greater( input.ID, 0 );
// the members of the input object and the output object must be equal
var output = repo.Get(input.ID);
Assert.AreNotEqual( input, output );
Assert.AreEqual( input.Title, output.Title );
Assert.AreEqual( input.Body, output.Body );
Assert.AreEqual( input.Forum, output.Forum );
Assert.AreEqual( input.UserID, output.UserID );
unitOfWork.Dispose();
}
示例5: Empty_Get_Nonexisting_Item_2
public void Empty_Get_Nonexisting_Item_2()
{
var repository = new Repository<User>();
var result = repository.Get(200000);
Assert.IsNull(result);
}
示例6: Application_AuthenticateRequest
protected void Application_AuthenticateRequest(Object sender,
EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id =
(FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
// Get the stored user-data, in this case, our roles
IRepository<User> UserRepository = new Repository<User>();
User user = UserRepository.Get(u => u.UserName == HttpContext.Current.User.Identity.Name).SingleOrDefault();
string userData = "";
if (user != null && user.Role.IsAuthor)
{
userData = "Author";
}
if (user != null && user.Role.IsAdmin)
{
userData = "Admin";
}
string[] roles = userData.Split(',');
HttpContext.Current.User = new GenericPrincipal(id, roles);
}
}
}
}
示例7: Page_Load
protected void Page_Load( object sender, EventArgs e )
{
var url = ConfigurationManager.AppSettings.Get( "CLOUDANT_URL" );
var connection = new Connection( new Uri( url ) );
if ( !connection.ListDatabases().Contains( "gmkreports" ) )
{
connection.CreateDatabase( "gmkreports" );
}
var repository = new Repository<Report>( connection.CreateSession( "gmkreports" ) );
var report = new Report { ID = Guid.NewGuid(), Type = 1, AccessionNumber = "123", Contents = "abcd" };
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Reset();
watch.Start();
var id = repository.Save( report ).Id;
var retrievedReport = repository.Get( id );
watch.Stop();
if ( retrievedReport.ID == report.ID && retrievedReport.Type == report.Type && retrievedReport.AccessionNumber == report.AccessionNumber && retrievedReport.Contents == report.Contents )
{
_label.Text = watch.ElapsedMilliseconds.ToString();
}
else
{
_label.Text = "Error";
}
}
示例8: Get_WithANonExistingID_ShouldReturnDefaultElement
public void Get_WithANonExistingID_ShouldReturnDefaultElement()
{
var repository = new Repository<User>();
var result = repository.Get(1);
Assert.AreEqual(null, result);
}
示例9: Init
/// <summary>
/// Creates all resources
/// </summary>
public static void Init()
{
var resourceRepository = new Repository<Resource>();
if (resourceRepository.Get().Count == 0)
{
resourceRepository.Create(
new Resource()
{
Name = "Metal",
Description = "Basic resource used to build",
InitialValue = 200.0
}
);
resourceRepository.Create(
new Resource()
{
Name = "Carbon",
Description = "Resource used as basic organic building block",
InitialValue = 300.0
}
);
resourceRepository.Create(
new Resource()
{
Name = "Fule",
Description = "Used to power other buildings",
InitialValue = 100.0
}
);
}
}
示例10: SRVCUpdateLogins
private IEnumerable<EmployeeLogin> SRVCUpdateLogins(Helpers.Log.SessionInfo logSession, Repository.Logic.Repository rep,
long employeeId, IEnumerable<string> addLogins, IEnumerable<string> removeLogins)
{
#pragma warning disable 618
logSession.Add($"Try to get employee with id = {employeeId}");
var emp = rep.Get<Repository.Model.Employee>(e => e.EmployeeId == employeeId, false, new string[] { "Logins" }).FirstOrDefault();
if (emp == null)
throw new Exception(string.Format(Properties.Resources.STUFFINGSERVICE_EmployeeNotFound, employeeId));
var existedLogins = emp.Logins.Select(r => r.DomainLogin);
#region Add logins
if (addLogins != null && addLogins.Any())
{
logSession.Add($"Add logins...");
var addLoginsUpper = addLogins
.Except(existedLogins)
.ToArray()
.Select(r => rep.New<Repository.Model.EmployeeLogin>((er) =>
{
er.EmployeeLoginId = emp.EmployeeId;
er.DomainLogin = r;
}))
.ToArray();
logSession.Add($"Add this logins {addLoginsUpper.Concat(r => r.DomainLogin, ",")} for employee id = {employeeId}");
foreach (var r in addLoginsUpper)
emp.Logins.Add(r);
rep.AddRange(addLoginsUpper, saveAfterInsert: false);
}
#endregion
#region Remove rights
if (removeLogins != null && removeLogins.Any())
{
logSession.Add($"Remove logins...");
var removeLoginsUpper = removeLogins
.Intersect(existedLogins)
.ToArray()
.Join(emp.Logins, r => r, er => er.DomainLogin.ToUpper(), (r, er) => er)
.ToArray();
logSession.Add($"Remove this logins {removeLoginsUpper.Concat(r => r.DomainLogin, ",")} for employee id = {employeeId}");
foreach (var r in removeLoginsUpper)
emp.Logins.Remove(r);
rep.RemoveRange(removeLoginsUpper, saveAfterRemove: false);
}
#endregion
rep.SaveChanges();
return emp.Logins.Select(er => AutoMapper.Mapper.Map<EmployeeLogin>(er));
#pragma warning restore 618
}
示例11: TestGetWhitNoEmptyRepository2
public void TestGetWhitNoEmptyRepository2()
{
int input = It.IsAny<int>();
Repository<int> repository = new Repository<int>();
repository.Add(input);
var actualResult = repository.Get(1);
Assert.AreEqual(input, actualResult);
}
示例12: no_events_return_null_ar
public void no_events_return_null_ar()
{
var id = "hhh";
_stream.Stub(s => s.GetEventStream(id)).Return(new List<object>());
var repo = new Repository<StandardARWithPublicMethods>(_stream);
Assert.Null(repo.Get(id));
}
示例13: Setup
public void Setup()
{
var eventStore = new TestEventStore();
var eventPublisher = new TestEventPublisher();
var snapshotStore = new NullSnapshotStore();
var rep = new Repository<TestSnapshotAggreagate>(eventStore, snapshotStore, eventPublisher);
_aggregate = rep.Get(Guid.NewGuid());
}
示例14: GetByIdExistingElement
public void GetByIdExistingElement()
{
Repository<User> testRepository = new Repository<User>();
var user = new User("username", "parola", Roles.User);
testRepository.Add(user);
Assert.AreEqual(testRepository.Get(1), user);
}
示例15: should_be_able_to_insert_a_users
public void should_be_able_to_insert_a_users()
{
var repository = new Repository(NHhelper.GetSessionFactory);
var user = new User { Name = "TestUser", Email = "[email protected]", Password = "testpassword", Role = 2 };
repository.Save(user);
var user1 = repository.Get<User>(user.Id);
Assert.AreEqual("TestUser", user1.Name);
}