Hello,

I'm having problems with a simple case that results in generating invalid SQL. 
This query:
var persons = from p in ActiveRecordLinq.AsQueryable<Person>()
              select new
                         {
                             p.Id,
                             p.FirstName,
                             p.LastName,
                             p.UserName,
                             p.Bookings
                         };

results in the following sql:
select person0_.ID as col_0_0_, person0_.FirstName as col_1_0_, 
person0_.LastName as col_2_0_, person0_.UserName as col_3_0_, . as col_4_0_, 
bookings1_.ID as ID0_, bookings1_.StartTime as StartTime0_, bookings1_.EndTime 
as EndTime0_, bookings1_.CustomerName as Customer4_0_, 
bookings1_.CustomerPhoneNumber as Customer5_0_, bookings1_.JobDescription as 
JobDescr6_0_, bookings1_.CreatedByPersonID as CreatedB7_0_ from dbo.Person 
person0_ inner join dbo.Booking bookings1_ on person0_.ID=bookings1_.PersonId

Notice how the 5th column is missing.

while:
var persons2 = from p in ActiveRecordLinq.AsQueryable<Person>() select p;

works as expected. The related classes are attached.

/Christian

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

using System;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using DataAccess;

namespace Models
{
    [ActiveRecord(Table = "Booking", Schema = "dbo")]
    public class Booking : ActiveRecordBase
    {
        [PrimaryKey(Column = "ID")]
        public virtual int Id { get; set; }

        [Property(Column = "StartTime", NotNull = true)]
        public virtual DateTime StartTime { get; set; }

        [Property(Column = "EndTime", NotNull = true)]
        public virtual DateTime EndTime { get; set; }

        [Property(Column = "CustomerName", Length = 512, NotNull = true)]
        public virtual string CustomerName { get; set; }

        [Property(Column = "CustomerPhoneNumber", Length = 512, NotNull = true)]
        public virtual string CustomerPhoneNumber { get; set; }

        [Property(Column = "JobDescription")]
        public virtual string JobDescription { get; set; }

        [BelongsTo(Column = "CreatedByPersonID")]
        public virtual Person CreatedByPerson { get; set; }
        }
}
using System.Collections.Generic;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using DataAccess;

namespace Models
{
    [ActiveRecord(Table = "Person", Schema = "dbo")]
    public class Person : ActiveRecordBase
    {
        private IList<Booking> _bookings = new List<Booking>();

        [PrimaryKey(Column = "ID")]
        public virtual int Id { get; set; }

        [Property(Column = "UserName", NotNull = true)]
        public virtual string UserName { get; set; }

        [Property(Column = "FirstName", NotNull = true)]
        public virtual string FirstName { get; set; }

        [Property(Column = "LastName", NotNull = true)]
        public virtual string LastName { get; set; }

        [Property(Column = "Password")]
        public virtual string Password { get; set; }

        [Property(Column = "LoginDisabled")]
        public virtual bool LoginDisabled { get; set; }

        [HasMany(typeof(Booking), Table = "Booking", ColumnKey = "PersonId", 
Cascade = ManyRelationCascadeEnum.AllDeleteOrphan)]
        public virtual IList<Booking> Bookings
        {
            get { return _bookings; }
            set { _bookings = value; }
        }
    }
}

Reply via email to