本文整理汇总了C#中UnitOfWork.CreateRepository方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.CreateRepository方法的具体用法?C# UnitOfWork.CreateRepository怎么用?C# UnitOfWork.CreateRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.CreateRepository方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
try
{
using (IUnitOfWork uow = new UnitOfWork(new Guid("5B479CE2-4BBC-4F9E-8539-6A6BC2DD099D")))
{
User user = null;
UserProfile userProfile = null;
uow.CreateRepository<UserProfile>();
uow.CreateRepository<User>();
var userProfileRepository = uow.GetRepository<UserProfile>();
var userRepository = uow.GetRepository<User>();
//Create Profile
userProfile = new UserProfile();
userProfile.Name = "Developpers";
userProfile.Description = "Developpers Group";
var profileAdded = userProfileRepository.Insert(userProfile);
//Create User
user = new User();
user.UserName = "Leonel Vasconcelos";
user.Login = "gurdurix";
user.Password = "123456";
user.ProfileUser = profileAdded;
userRepository.Insert(user);
uow.SaveChanges();
user = null;
userProfile = null;
//Get user information
user = userRepository.GetEntityBy(new FindEntitySpecification<User>(p=>p.Login.Equals("gurdurix")));
Console.WriteLine($"{user.Id} >> {user.Login} ({user.UserName})");
//var user = userRepository.GetEntityByPrimaryKey(new FindEntityByIdSpecification<User>(new Guid("97DD8E65-76F1-4C12-A0FA-D9D07032C81B")));
//uow.CreateRepository<UserProfile>();
//IRepository<UserProfile> userProfileRepository = uow.GetRepository<UserProfile>();
//userProfileRepository.Insert(new UserProfile(
//var users = uow.GetRepository<User>().GetAllEntities(
// new FindEntitySpecification<User>(p => p.ProfileUser.ID.Equals(new Guid("E50C5924-B88B-44D7-B89A-1F30244A1817")))
// .Not(new FindEntityByIdSpecification<User>(new Guid("D9579A46-1B9F-4C09-A02D-E4A6D4096E00"))));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}