Unless absolutely necessary, use IList<T> instead of the non-generic IList.
Also, if the collection has set semantics, consider using ISet<T> instead of
IList<T>.

--
Mauricio



On Mon, Feb 7, 2011 at 10:07 AM, smiler <[email protected]> wrote:

> Hello,
>
> I've recently started testing Castle ActiveRecord but I've found a
> problem that I don't know how to solve. I'd like to use the following
> query (one that I've used in the same project but using Entity
> Framework):
>
> var persons = from p in ActiveRecordLinq.AsQueryable<Person>()
>              where p.Contracts.Count(c => c.ToDate <= DateTime.Now) >
> 0
>              select p;
>
> My Person class looks like the following:
>
>    [ActiveRecord(Table = "Person", Schema = "dbo")]
>    public class Person : ActiveRecordBase<Person>
>    {
>        private IList contracts = new ArrayList();
>
>        [PrimaryKey(Generator = PrimaryKeyType.Native)]
>        public virtual int ID { get; set; }
>
>        /* some basic properties here */
>
>        [HasMany(typeof(Contract), Table = "Contract", ColumnKey =
> "personid", Inverse = true, Lazy = true, RelationType =
> RelationType.Set)]
>        public virtual IList Contracts
>        {
>            get { return contracts; }
>            set { contracts = value; }
>        }
>    }
>
> and my Contract class:
>
>    [ActiveRecord(Table="Contract", Schema="dbo")]
>    public class Contract : ActiveRecordBase<Contract>
>    {
>        [PrimaryKey(Generator = PrimaryKeyType.Native)]
>        public virtual int ID { get; set; }
>
>        /* more non-related properties here */
>
>        [BelongsTo("personid", NotNull = true)]
>        public virtual Person Person { get; set; }
>
>        [Property(Column = "FromDat", NotNull = true)]
>        public virtual DateTime FromDate { get; set; }
>
>        [Property(Column = "ToDat")]
>        public virtual DateTime? ToDate { get; set; }
>    }
>
> When trying to build this the compiler will tell me:
>
>
> 'System.Collections.IList' does not contain a definition for 'Count'
> and no extension method 'Count' accepting a first argument of type
> 'System.Collections.IList' could be found (are you missing a using
> directive or an assembly reference?).
>
> I guess that's because IList doesn't support the Count method with a
> predicate. I guess what I need is a collection of IQueryable<T> in the
> Person class but I can't get that to work. Any tips or hints?
>
> --
> 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.
>
>

-- 
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.

Reply via email to