大家好,我在调试一个程序是,报了一个这样的错:"Dbc(Design By Contract)设计契约违背。(DataAccessor要求在事务中进行,但当前操作未在事务中!)",请版主给帮忙看看的.下面是源码:
using System;
using System.Collections.Generic;
using System.Text;
using Eai.Data;
namespace OA.Biz.Domain
{
public class AbstractManager<T>
where T : new()
{
public IDataAccessor DataAccessor
{
get
{
return DataAccessContext.Current.GetDataAccessor();
}
}
public List<T> GetList()
{
System.Collections.IList oldList = DataAccessor.Query("From " + typeof(T));
List<T> list = ToGenericList(oldList);
return list;
}
public static List<T> ToGenericList(System.Collections.IList oldList)
{
List<T> list = new List<T>();
foreach (T t in oldList)
{
list.Add(t);
}
return list;
}
public virtual void Create(T t)
{
DataAccessor.Create(t);
}
public virtual void Delete(T t)
{
DataAccessor.Delete(t);
}
public virtual void Delete(Guid id)
{
Delete(Get(id));
}
public virtual void Update(T t)
{
DataAccessor.Update(t);
}
public virtual T Get(string id)
{
return Get(new Guid(id));
}
public virtual T Get(Guid id)
{
return (T)DataAccessor.Get(typeof(T), id); //错误处
}
public virtual T Get(Guid? id)
{
if (id == null) return new T();
return Get((Guid)id);
}
}
}