castle-activerecord

How to define recursive Property in Castel ActiveRecord?

Hi, Suppose you have a class named MyClass. MyClass should have a property named Parent, Parent must be of type MyClass itslef. It is necessary because MyClass wants to hold a tree structure. How can it be done? ...

Unable to cast object of type 'MyType' to type 'Castle.Proxies.MyType'.

Hi all, In which situation following error occurs? Unable to cast object of type 'MyType' to type 'Castle.Proxies.MyType'. UPDATE: I got this error message while binding MyType.FindAllByProperty("col1", "foo"); to a GridView (exactly a Telerik's one: RadGrid). This error is not occuring every time, just sometimes. Here is markup of...

How to convert class to inherited class while using ActiveRecord

I've got a class Project and a class Case, which inherits from Project. When having a list of Projects we might decide later on to make a Case of the selected Project. How can I achieve this? Project: [ActiveRecord (Table = "projects", Lazy = true), JoinedBase] public class Project : ActiveRecordValidationBase<Project> { priva...

Castle ActiveRecord FK as discriminator column

I have just started using castle active record and i am having some problems using a foreign key as the discriminator column. I get the error "Invalid index 2 for this SqlParameterCollection with Count=2." The tables i am using are:- TABLE MemberRoles [Id] [int] IDENTITY NOT NULL, [Name] [varchar] NOT NULL TABLE Members [Id] [int] IDE...

onFlushDirty triggered twice

Hi everybody, lately I have been using a lot Castle ActiveRecord framework and it has worked fine until I found a strange behaviour. For some reasons I don't understand the onFlushDirty is triggered twice in some situations. It is even triggered when I make a simple query. I'm really confused cause I'm trying to make auditing and as I re...

Castle ActiveRecord - sorting by custom sql expression

Hey, I'm using MonoRail ActiveRecord and have a query that returns businesses within a certain number of miles of a user. I was able to use Expression.Sql to do the distance calculation, however I now need to sort the results by the distance. How do I add a custom sql expression into criteria.AddOrder()? Here's the code: var criteria =...

Why ActiveRecordHooksBase.OnUpdate does not work in cascaded mode?

Suppose we have two entities Blog and Post that Blog has many Posts. Post is saved indirectly through Blog. When I override OnUpdate in Post, it causes to save Posts that have null Blog. In the other hand overriding OnUpdate in Post causes not saving it properly. Someone else have had same problem. The code is: protected override void ...

Can I access generated query without executing it?

I know how to enable debugging so all queries that get run appear in my console. Is there any way to simply output the generated query without executing it? ...

ActiveRecord: how to find constraints?

I'm kind of new to ActiveRecord (using CastleProject) and gaining knowledge step by step. Now I'm running into another situation. I've got a Media class that is used in some other classes: Content, Case and Service. Now when I want to delete a Media class, I want to check if there are any constraints with the previous named classes. I...

Can I attach criterias for a HasMany entity?

I have an Incident class that uses the HasMany attribute to a Location class. All works using the static Find methods. But I need to add a where clause to the Location table. I can use the Where attribute but I don't always want that clause when fetching results. Is there any way to maybe use DetachedCriteria or something similar while ...

What is the problem with my Castle ActiveRecord web.config

I'm trying to upgrade my ASP.NET MVC 1 website to version 2. While doing this I'm having to update all of my other assemblies as well. This includes Castle's ActiveRecord dll as well. Here is the error I'm getting: Configuration Error Description: An error occurred during the processing of a configuration file required to se...

Castle Activerecord object doesn't refresh

I am using castle active record, I load an enity using the .Find() method, after updating the database i call entity.Refresh() but the entity doesn't refresh, the data that i changed in the database is not reflected in the state of the entity. I am at a total loss as to how to get this to work. ...

Generalizing a Fetch() function for data sources

I have a Repository that should adapt itself to any kind of data source. This includes certain types of web services, databases (using ActiveRecord and NHibernate) and even flat files. For ActiveRecord I have EnumerateQuery(IActiveRecordQuery query) which returns an IEnumerable just like I need but the interface is undocumented. What exa...

Limiting fields in Select statement generated by Linq to Castle ActiveRecord

Hi all! I'm using ActiveRecord and LinqToActiveRecord to query my database. The problem is, that the generated SQL statement from my LINQ expression always tries to select all possible fields, including joined tables, when this is not needed. For example, I have these database tables: Table: MasterTable Id (int) ChildId (int) <- refere...

Mapping lookup tables

I have several tables that all reference the same lookup table. Is it generally a good idea to attach the BelongsTo attribute to each table that references a FK from a lookup table? Or should I model the foreign keys as a property and simply link the two tables while constructing my detached criteria? ...

What is the preferred way of using unsupported SQL functions or clauses with Castle/NHibernate?

I modeled all of my tables and already ported most of my queries using detached criteria's. All is working very well however I'm at a point where I don't know how to advance. I have a sub-query that uses Oracle's "connect by" clause. How do developers typically overcome that limitation of Castle/NHibernate? I am using the latest version...

How can I extend a model from a different assembly?

How can I add a property to a model that was created in an other assembly. We have many applications ranging from desktop applications to web applications so I have class library with each model needed along with their relationships. I am very easily able to reference my class library and query what is needed. However, due to the fact th...

Why Castle Active Record's `FindAllByProperty` calls `OnUpdate`?

When I call FindAllByProperty it calls OnUpdate in castle Active Record, This causes an stack overflow because I do some duplicating check on OnUpdate an instance. Consider following code. Why it calls OnUpdate? How can stop it? protected override void OnUpdate() { if (FindAllByProperty("Title", this.Title).Length > 1) throw...

Active Record/Nhibernate TransactionScopes problems

Hi ! This question is purely AR related. Let's say I have 2 layers in my web/wcf application - DataLayer and BusinessLayer. DataLayer contains almost atomic operations that work on mappings (find, get, save, special find, cross find , etc. :) ). There is a lot of HQL or Criterias. There's no SessionScopes used in this layer. Some of my ...

Using DetachedCriteria to return generic list of non-AR type

I'm fiddling with my repository class and attempted to execute a query with a detached criteria. However, it doesn't seem to like me setting the result transformer to a non AR-type. public class IncidentRepository { public static IList<AuditReport> GetAllIncidentsToAudit() { DetachedCriteria dc = DetachedCriteria.For<Inc...