Repository always return a zero field

Topics: Customizing Orchard, Writing modules
Jul 1, 2011 at 6:05 AM

Another wierd error . I created an Employee content type , then I create another content type Children , its record and part declare like below

 

public class ChildrenPartRecord : ContentPartRecord
    {
        public virtual int EmployeeId { get; set; }
        public virtual string Name { get; set; }
        public virtual DateTime? DOB { get; set; }
        
    }

    public class ChildrenPart : ContentPart<ChildrenPartRecord>
    {
        public int EmployeeId
        {
            get { return Record.EmployeeId; }
            set { Record.EmployeeId = value; }
        }
        public string Name
        {
            get { return Record.Name; }
            set { Record.Name = value; }
        }

        public DateTime? DOB
        {
            get { return Record.DOB; }
            set { Record.DOB = value; }
        }        

    }

Migration
SchemaBuilder.CreateTable("ChildrenPartRecord", table => table.ContentPartRecord()
                                                                    .Column<int>("EmployeeId")
                                                                    .Column<string>("Name")
                                                                    .Column<DateTime>("DOB"));

The create method :

 

public ChildrenPart CreateChildren(string name, string DOB, int employeeId) {
            var item = _orchardServices.ContentManager.New<ChildrenPart>("Children");

            item.Record.Name = name;
            if (DOB != null)
                item.Record.DOB = DateTime.Parse(DOB);
            item.Record.EmployeeId = employeeId;

            _orchardServices.ContentManager.Create(item);
            return item;
        }

When I click create a child , the Name and DOB field work normally , but the EmployeeId field is always NULL . All is correct when I debug the Create method
I tried to modified this field on SQL server to the current Employee (for example here EmployeeId is 142)
But when I list it with this method:

            return id == 0 ? new List<ChildrenPartRecord>() : (_childrenRepository.Table.Count() > 0 ?
                _childrenRepository.Table.Where(c => c.EmployeeId == id).ToList() : new List<ChildrenPartRecord>());

It will result an error about Nhibernate : cannot resolve property EmployeeId of ChildrenPartRecord

And when I tried change it like
if(id == 0)
                return new List<ChildrenPartRecord>();

            var l1 = _childrenRepository.Table.ToList();
            var l2 = l1.Where(l => l.EmployeeId== id).ToList();

            if (l2.Count > 0)
                return l2;
            else return new List<ChildrenPartRecord>();

l1 count is 1 , but EmployeeId field is 0 , when in database it is 142
anyone help plz