我首先使用EF6.1.3代码和WCF 使用包含功能时,获取错误“循环引用”
using (var db = new AvanEntites())
{
db.Configuration.ProxyCreationEnabled = false;
db.Configuration.LazyLoadingEnabled = false;
data = db.WorkflowPositions.Include("RolePermissions").Include("RolePermissions.Application").AsNoTracking.ToArray();
}
我的课程:
public class BaseModel : INotifyPropertyChanged
{
private bool _isActive;
private DateTime? _lastUpdateTime;
private DateTime? _creationDate;
private long? _lastUpdatedBy;
private long? _createdBy;
public long? CreatedBy
{
get { return _createdBy; }
set
{
if (value == _createdBy) return;
_createdBy = value;
OnPropertyChanged(nameof(CreatedBy));
}
}
public long? LastUpdatedBy
{
get { return _lastUpdatedBy; }
set
{
if (value == _lastUpdatedBy) return;
_lastUpdatedBy = value;
OnPropertyChanged(nameof(LastUpdatedBy));
}
}
public DateTime? CreationDate
{
get { return _creationDate; }
set
{
if (value.Equals(_creationDate)) return;
_creationDate = value;
OnPropertyChanged(nameof(CreationDate));
}
}
public DateTime? LastUpdateTime
{
get { return _lastUpdateTime; }
set
{
if (value.Equals(_lastUpdateTime)) return;
_lastUpdateTime = value;
OnPropertyChanged(nameof(LastUpdateTime));
}
}
public bool IsActive
{
get { return _isActive; }
set
{
if (value == _isActive) return;
_isActive = value;
OnPropertyChanged(nameof(IsActive));
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public partial class WorkflowPosition:BaseModel
{
private ObservableCollection<WorkflowContractPosition> _workflowContractPositions;
private string _namePosition;
private long _id;
private ObservableCollection<RolePermission> _rolePermissions;
// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public WorkflowPosition()
{
WorkflowContractPositions = new ObservableCollection<WorkflowContractPosition>();
}
public long Id
{
get { return _id; }
set
{
if (value == _id) return;
_id = value;
OnPropertyChanged(nameof(Id));
}
}
public string NamePosition
{
get { return _namePosition; }
set
{
if (value == _namePosition) return;
_namePosition = value;
OnPropertyChanged(nameof(NamePosition));
}
}
// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ObservableCollection<WorkflowContractPosition> WorkflowContractPositions
{
get { return _workflowContractPositions; }
set
{
if (Equals(value, _workflowContractPositions)) return;
_workflowContractPositions = value;
OnPropertyChanged(nameof(WorkflowContractPositions));
}
}
public virtual ObservableCollection<RolePermission> RolePermissions
{
get
{
return _rolePermissions;
}
set
{
if (Equals(value, _rolePermissions)) return;
_rolePermissions = value;
OnPropertyChanged(nameof(RolePermissions));
}
}
}
public class RolePermission:BaseModel
{
private WorkflowPosition _workflowPosition;
private Application _application;
private long _applicationId;
private long _positionId;
private long _permissionId;
public RolePermission()
{
}
[Key]
public long PermissionId
{
get { return _permissionId; }
set
{
if (value == _permissionId) return;
_permissionId = value;
OnPropertyChanged(nameof(PermissionId));
}
}
public long PositionId
{
get { return _positionId; }
set
{
if (value == _positionId) return;
_positionId = value;
OnPropertyChanged(nameof(PositionId));
}
}
public long ApplicationId
{
get { return _applicationId; }
set
{
if (value == _applicationId) return;
_applicationId = value;
OnPropertyChanged(nameof(ApplicationId));
}
}
public virtual Application Application
{
get { return _application; }
set
{
if (Equals(value, _application)) return;
_application = value;
OnPropertyChanged(nameof(Application));
}
}
public virtual WorkflowPosition WorkflowPosition
{
get { return _workflowPosition; }
set
{
if (Equals(value, _workflowPosition)) return;
_workflowPosition = value;
OnPropertyChanged(nameof(WorkflowPosition));
}
}
}
public class Application : BaseModel
{
private ObservableCollection<RolePermission> _rolePermissions;
private string _applicationName;
private long _applicationId;
private string _madule;
public Application() { }
[Key]
public long ApplicationId
{
get { return _applicationId; }
set
{
if (value == _applicationId) return;
_applicationId = value;
OnPropertyChanged(nameof(ApplicationId));
}
}
public string ApplicationName
{
get { return _applicationName; }
set
{
if (value == _applicationName) return;
_applicationName = value;
OnPropertyChanged(nameof(ApplicationName));
}
}
public string Madule
{
get { return _madule; }
set
{
if (value == _madule) return;
_madule = value;
OnPropertyChanged(nameof(Madule));
}
}
public virtual ObservableCollection<RolePermission> RolePermissions
{
get { return _rolePermissions; }
set
{
if (Equals(value, _rolePermissions)) return;
_rolePermissions = value;
OnPropertyChanged(nameof(RolePermissions));
}
}
}