流畅的nhibernate映射安全异常

时间:2013-12-20 14:15:54

标签: 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 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();
    }
}

相关的映射类是

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");
   }
}

当我尝试从时间表中访问emplyee时出现安全异常错误,反之亦然。

IQuery query = session.CreateQuery(String.Format("from {0} where {1} ='{2}'", "Timesheet", "Employee", 1));
IList<Timesheet> timeSheet=  query.List<Timesheet>();

1 个答案:

答案 0 :(得分:0)

您的服务器似乎正在中等可信上下文中运行您的Web应用程序。这需要你在nhibernate中更改一些设置才能运行nh。

城堡代理人最有可能是坏人......

尝试按照explained here步骤进行操作。