我收到此错误:
具有相同标识符值的不同对象已与会话关联:63,实体:Core.Domain.Model.Employee
在我的ASP.NET MVC控制器操作中,我这样做:
public ActionResult Index(int? page)
{
int totalCount;
Employee[] empData = _employeeRepository.GetPagedEmployees(page ?? 1, 5, out totalCount);
EmployeeForm[] data = (EmployeeForm[]) Mapper<Employee[], EmployeeForm[]>(empData);
PagedList<EmployeeForm> list = new PagedList<EmployeeForm>(data, page ?? 1, 5, totalCount);
if (Request.IsAjaxRequest())
return View("Grid", list);
return View(list);
}
public ActionResult Edit(int id)
{
ViewData[Keys.Teams] = MvcExtensions.CreateSelectList(
_teamRepository.GetAll().ToList(),
teamVal => teamVal.Id,
teamText => teamText.Name);
return View(_employeeRepository.GetById(id) ?? new Employee());
}
[HttpPost]
public ActionResult Edit(
Employee employee,
[Optional, DefaultParameterValue(0)] int teamId)
{
try
{
var team …Run Code Online (Sandbox Code Playgroud) 可能重复:
如何将LINQ表达式合并为一个?
public bool IsUnique(params Expression<Func<Employee, bool>>[] properties)
{
var combinedProperties = Combine(properties);
var rowCount = _session.QueryOver<Employee>().Where(combinedProperties).ToRowCountQuery().RowCount();
return rowCount == 0;
}
Expression<Func<Employee, bool>> Combine(Expression<Func<Employee, bool>>[] properties)
{
???
}
Run Code Online (Sandbox Code Playgroud)
用法:
var isUnique = _employeeRepository.IsUnique(x => x.FirstName == commandMessage.FirstName, x => x.LastName == commandMessage.LastName);
Run Code Online (Sandbox Code Playgroud)
有没有一种方法将谓词与AND运算符相结合?
我正在寻找用于代码导航和探索的优秀Visual Studio 6 Addins.
例如,我希望具有显示Resharper等方法的输入和输出调用的功能.
此外,我正在寻找一个更简单的代码导航.
你有什么建议吗?
我只需要在单元测试中模拟外部依赖吗?
如果我想测试的方法依赖于同一个程序集中的另一个类,该怎么办?我是否必须模拟依赖关系以确保只测试一件事并进行单元测试而不是集成测试?
集成测试是一般测试依赖项的测试,还是我必须区分内部和外部依赖项?
一个例子是一个方法,它有2000行代码和5个方法调用(所有方法来自同一个程序集).
我将服务名称传递给参数列表,但是当我查看安装程序上下文时,它不存在:
args = new[] { Assembly.GetExecutingAssembly().Location, "/ServiceName=WinService1" };
ManagedInstallerClass.InstallHelper(args);
Run Code Online (Sandbox Code Playgroud)
为什么键值对不会传递到安装程序上下文中?
public override void Install(IDictionary stateSaver)
{
foreach (var param in Context.Parameters)
{
// ServiceName is not available in the Parameters collection
}
}
Run Code Online (Sandbox Code Playgroud) c# ×3
expression ×1
installutil ×1
lambda ×1
linq ×1
navigation ×1
nhibernate ×1
unit-testing ×1
vb6 ×1