mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-08-23 22:11:35 +08:00
修复机构添加编辑的异常的bug
This commit is contained in:
parent
18d6d416d7
commit
9faedc1260
@ -43,6 +43,8 @@ namespace OpenAuth.App
|
|||||||
UnitWork.Update(a);
|
UnitWork.Update(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UnitWork.Save();
|
||||||
|
|
||||||
return org.Id;
|
return org.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,12 +18,6 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
public ActionResult Assign(string firstId, string key)
|
|
||||||
{
|
|
||||||
ViewBag.FirstId = firstId;
|
|
||||||
ViewBag.ModuleType = key;
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string LoadForUser(string firstId)
|
public string LoadForUser(string firstId)
|
||||||
{
|
{
|
||||||
@ -72,7 +66,6 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除指定ID的组织
|
/// 删除指定ID的组织
|
||||||
/// <para>Id为逗号分开的字符串</para>
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>System.String.</returns>
|
/// <returns>System.String.</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
@ -78,7 +78,13 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
{
|
{
|
||||||
var org = user.Orgs.SingleOrDefault(u => u.Id == orgId);
|
var org = user.Orgs.SingleOrDefault(u => u.Id == orgId);
|
||||||
if (org == null)
|
if (org == null)
|
||||||
throw new Exception("未能找到指定对象信息");
|
{
|
||||||
|
return JsonHelper.Instance.Serialize(new TableData
|
||||||
|
{
|
||||||
|
msg ="未找到指定的节点",
|
||||||
|
code = 500,
|
||||||
|
});
|
||||||
|
}
|
||||||
cascadeId = org.CascadeId;
|
cascadeId = org.CascadeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ namespace OpenAuth.Repository
|
|||||||
|
|
||||||
private IQueryable<T> Filter(Expression<Func<T, bool>> exp)
|
private IQueryable<T> Filter(Expression<Func<T, bool>> exp)
|
||||||
{
|
{
|
||||||
var dbSet = Context.Set<T>().AsQueryable();
|
var dbSet = Context.Set<T>().AsNoTracking().AsQueryable();
|
||||||
if (exp != null)
|
if (exp != null)
|
||||||
dbSet = dbSet.Where(exp);
|
dbSet = dbSet.Where(exp);
|
||||||
return dbSet;
|
return dbSet;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
using System.Data.Entity;
|
using System.Data.Entity;
|
||||||
|
using System.Data.Entity.Infrastructure;
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Mapping;
|
using OpenAuth.Repository.Mapping;
|
||||||
|
|
||||||
@ -25,6 +26,11 @@ namespace OpenAuth.Repository
|
|||||||
{
|
{
|
||||||
// 关闭语义可空判断
|
// 关闭语义可空判断
|
||||||
Configuration.UseDatabaseNullSemantics = true;
|
Configuration.UseDatabaseNullSemantics = true;
|
||||||
|
|
||||||
|
//与变量的值为null比较
|
||||||
|
//ef判断为null的时候,不能用变量比较:https://stackoverflow.com/questions/682429/how-can-i-query-for-null-values-in-entity-framework?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
||||||
|
(this as IObjectContextAdapter).ObjectContext.ContextOptions.UseCSharpNullComparisonBehavior = true;
|
||||||
|
Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenAuthDBContext(string nameOrConnectionString)
|
public OpenAuthDBContext(string nameOrConnectionString)
|
||||||
|
@ -85,9 +85,14 @@ namespace OpenAuth.Repository
|
|||||||
public void Update<T>(T entity) where T:class
|
public void Update<T>(T entity) where T:class
|
||||||
{
|
{
|
||||||
var entry = this.Context.Entry(entity);
|
var entry = this.Context.Entry(entity);
|
||||||
//todo:如果状态没有任何更改,会报错
|
|
||||||
entry.State = EntityState.Modified;
|
entry.State = EntityState.Modified;
|
||||||
|
|
||||||
|
//如果数据没有发生变化
|
||||||
|
if (!this.Context.ChangeTracker.HasChanges())
|
||||||
|
{
|
||||||
|
entry.State = EntityState.Unchanged;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Delete<T>(T entity) where T:class
|
public void Delete<T>(T entity) where T:class
|
||||||
@ -136,7 +141,7 @@ namespace OpenAuth.Repository
|
|||||||
|
|
||||||
private IQueryable<T> Filter<T>(Expression<Func<T, bool>> exp) where T : class
|
private IQueryable<T> Filter<T>(Expression<Func<T, bool>> exp) where T : class
|
||||||
{
|
{
|
||||||
var dbSet = Context.Set<T>().AsQueryable();
|
var dbSet = Context.Set<T>().AsNoTracking().AsQueryable();
|
||||||
if (exp != null)
|
if (exp != null)
|
||||||
dbSet = dbSet.Where(exp);
|
dbSet = dbSet.Where(exp);
|
||||||
return dbSet;
|
return dbSet;
|
||||||
|
@ -23,7 +23,7 @@ namespace OpenAuth.UnitTest
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
var random = new Random();
|
var random = new Random();
|
||||||
int val = random.Next();
|
int val = random.Next();
|
||||||
@ -43,5 +43,17 @@ namespace OpenAuth.UnitTest
|
|||||||
Console.WriteLine(e.Message);
|
Console.WriteLine(e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
_app.Update(new Org
|
||||||
|
{
|
||||||
|
Id = "4bcdd85d-662f-42e4-94dc-19e3e98ef4dc",
|
||||||
|
Name = "测试",
|
||||||
|
ParentId = "57239263-0176-4ef9-a4b5-3491a04e2c6a"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user