Joe

Mister Doctor Professor
posts - 23, comments - 19, trackbacks - 134

Monday, June 02, 2008

ActiveRecord: could not resolve property

 

Because this has bitten me in the ass more than once.

When using ActiveRecord to query the database the following error occurs:

Failed: Castle.ActiveRecord.Framework.ActiveRecordException : Could not perform SlicedFindAll for ShoppingCart
  ----> NHibernate.QueryException : could not resolve property: UserId of: MyDomain.Core.ShoppingCart

ProblemThe Property values in the criteria are case sensitive.

Where the query looks like this:

        public ShoppingCart LoadCurrentBasket(string userId, Guid customerId)
        {
            DetachedCriteria criteria = DetachedCriteria.For<ShoppingCart>();
            criteria.Add(Expression.Eq("UserId", userId));
            criteria.Add(Expression.Eq("CustomerId", customerId));

            return ActiveRecordMediator<ShoppingCart>.FindFirst(criteria);
        }

 

And the class looks like this: 

    [ActiveRecord(Table = "Basket")]
    public class ShoppingCart
    {
        private IList<ShoppingCartItem> _LineItems = new List<ShoppingCartItem>();

        [PrimaryKey(PrimaryKeyType.Guid)]
        public Guid BasketID { get; set; }

        [Property("CustomerId")]
        public Guid CustomerID { get; set;}

        [Property("UserID")]
        public string UserID { get; set;}

///
///
///

    }

posted @ Monday, June 02, 2008 1:24 PM | Feedback (7) |

Powered by: