C# fluent nhibernate映射安全异常
以下代码在本地系统中运行良好,但在服务器中抛出错误C# fluent nhibernate映射安全异常,c#,fluent-nhibernate,C#,Fluent Nhibernate,以下代码在本地系统中运行良好,但在服务器中抛出错误 public class Employee { public virtual Int32 Emp_ID { get; set; } public virtual String Name { get; set; } public virtual String Email { get; set; } public virtual String Mobile { get; set; } public virtu
public class Employee
{
public virtual Int32 Emp_ID { get; set; }
public virtual String Name { get; set; }
public virtual String Email { get; set; }
public virtual String Mobile { get; set; }
public virtual String Address { get; set; }
public virtual String Username { get; set; }
public virtual String Password { get; set; }
public virtual String Designation { get; set; }
public virtual String Reference { get; set; }
public virtual Boolean IsWorking{get;set;}
public virtual IList<Timesheet> Timesheet { get; set; }
#region Object Overrides
/// <summary>
/// Method that checkes if the given User instance is equivalent to the current User Instance
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if (obj is Timesheet)
{
Timesheet compareTo = (Timesheet)obj;
return compareTo.Timesheet_ID.Equals(this.Timesheet);
}
else
{
return base.Equals(obj);
}
}
/// <summary>
/// ToString of Product Instance returns the Product Code
/// instead of the Itme Object's String representation
/// </summary>
/// <returns></returns>
public override string ToString()
{
return this.Name;
}
/// <summary>
/// Method that gets the Hash Code of the Object's Unique Identifier
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return this.Emp_ID.GetHashCode();
}
#endregion
}
public class Timesheet
{
public virtual Int32 Timesheet_ID { get; set; }
public virtual Employee Employee { get; set; }
public virtual Client Client { get; set; }
public virtual Project Project { get; set; }
public virtual Activity Activity { get; set; }
public virtual DateTime Date { get; set; }
public virtual String TimeSpent { get; set; }
public virtual String Comments { get; set; }
public virtual Boolean IsApproved { get; set; }
public Timesheet()
{
Employee = new Employee();
}
}
公共类员工
{
公共虚拟Int32 Emp_ID{get;set;}
公共虚拟字符串名称{get;set;}
公共虚拟字符串电子邮件{get;set;}
公共虚拟字符串Mobile{get;set;}
公共虚拟字符串地址{get;set;}
公共虚拟字符串用户名{get;set;}
公共虚拟字符串密码{get;set;}
公共虚拟字符串指定{get;set;}
公共虚拟字符串引用{get;set;}
公共虚拟布尔值正在工作{get;set;}
公共虚拟IList时间表{get;set;}
#区域对象覆盖
///
///方法,该方法检查给定用户实例是否与当前用户实例等效
///
///
///
公共覆盖布尔等于(对象对象对象)
{
如果(obj是时间表)
{
时间表比较对象=(时间表)对象;
返回compareTo.Timesheet_ID.Equals(此.Timesheet);
}
其他的
{
返回基数等于(obj);
}
}
///
///产品实例的ToString返回产品代码
///而不是Itme对象的字符串表示形式
///
///
公共重写字符串ToString()
{
返回此.Name;
}
///
///方法,该方法获取对象唯一标识符的哈希代码
///
///
公共覆盖int GetHashCode()
{
返回这个.Emp_ID.GetHashCode();
}
#端区
}
公共课时间表
{
公共虚拟Int32时间表\u ID{get;set;}
公共虚拟员工{get;set;}
公共虚拟客户端{get;set;}
公共虚拟项目{get;set;}
公共虚拟活动活动{get;set;}
公共虚拟日期时间日期{get;set;}
公共虚拟字符串timespunt{get;set;}
公共虚拟字符串注释{get;set;}
公共虚拟布尔值已批准{get;set;}
公共时间表()
{
雇员=新雇员();
}
}
相关的映射类包括
public class EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
// Table name as in database
Table("tblEmployee");
// Fields mapping to the Database
Id(x => x.Emp_ID).GeneratedBy.Increment();
Map(x => x.Name);
Map(x => x.Email);
Map(x => x.Mobile);
Map(x => x.Address);
Map(x => x.Username);
Map(x => x.Password);
Map(x => x.Designation);
Map(x => x.Reference);
Map(x => x.IsWorking);
HasManyToMany(x => x.Timesheet).Table("tblEmpTimesheet").ParentKeyColumn("Emp_ID").ChildKeyColumn("Timesheet_ID");
}
public class TimesheetMap
{
public TimesheetMap()
{
// Table name as in database
Table("tblEmpTimesheet");
// Fields mapping to the Database
Id(x => x.Timesheet_ID).GeneratedBy.Increment();
Map(x => x.Date);
Map(x => x.TimeSpent);
Map(x => x.Comments);
Map(x => x.IsApproved).Default("false");
// Relationships with Other Objects
References<Employee>(x => x.Employee).Column("Emp_ID");
}
}
公共类EmployeeMap:ClassMap
{
公共雇员地图()
{
//数据库中的表名
表(“受雇人”);
//映射到数据库的字段
Id(x=>x.Emp_Id).GeneratedBy.Increment();
Map(x=>x.Name);
Map(x=>x.Email);
地图(x=>x.Mobile);
映射(x=>x.Address);
映射(x=>x.Username);
映射(x=>x.Password);
地图(x=>x.1);
Map(x=>x.Reference);
Map(x=>x.IsWorking);
HasManyToMany(x=>x.Timesheet).Table(“tblEmpTimesheet”).ParentKeyColumn(“Emp_ID”).ChildKeyColumn(“Timesheet_ID”);
}
公共类时间表映射
{
公共时间表
{
//数据库中的表名
表(“tblEmpTimesheet”);
//映射到数据库的字段
Id(x=>x.Timesheet_Id).GeneratedBy.Increment();
地图(x=>x.Date);
Map(x=>x.timespunt);
地图(x=>x.Comments);
映射(x=>x.IsApproved)。默认值(“false”);
//与其他对象的关系
参考文献(x=>x.Employee).列(“Emp_ID”);
}
}
当我尝试从时间表或viceversa访问员工时引发安全异常错误
IQuery query = session.CreateQuery(String.Format("from {0} where {1} ='{2}'", "Timesheet", "Employee", 1));
IList<Timesheet> timeSheet= query.List<Timesheet>();
IQuery=session.CreateQuery(String.Format(“from{0},其中{1}='{2}'”,“时间表”,“员工”,1));
IList timeSheet=query.List();
您的服务器似乎正在中等可信上下文中运行您的web应用程序。这要求您更改nhibernate中的一些设置以使nh运行
最有可能的是castle代理的人是坏人
尝试按照步骤进行操作。什么类型的异常?stacktrace说什么?它说System.Security.SecurityException:该程序集不允许部分受信任的调用方。感谢您的帮助…我正在通过global.ascx进行流畅的设置,但不是像您提到的那样从web.config通过web.config更改设置…您尝试过了吗s受保护的无效应用程序_Start(){Initializer.RegisterBytecodeProvider(new EntityInjector());…}