castle-activerecord

Suggestions on how to map from Domain (ORM) objects to Data Transfer Objects (DTO)

The current system that I am working on makes use of Castle Activerecord to provide ORM (Object Relational Mapping) between the Domain objects and the database. This is all well and good and at most times actually works well! The problem comes about with Castle Activerecords support for asynchronous execution, well, more specifically th...

C# + Castle ActiveRecord: HasAndBelongsToMany and collections

Let's say I have many-to-many relationship (using the ActiveRecord attribute HasAndBelongsToMany) between Posts and Tags (domain object names changed to protect the innocent), and I wanted a method like FindAllPostByTags(IList<Tag> tags) that returns all Posts that have all (not just some of) the Tags in the parameter. Any way I could ac...

Castle-ActiveRecord Tutorial with .NET 3.5 broken?

Has anyone tried the ActiveRecord Intro Sample with C# 3.5? I somehow have the feeling that the sample is completely wrong or just out of date. The XML configuration is just plain wrong: <add key="connection.connection_string" value="xxx" /> should be : <add key="hibernate.connection.connection_string" value="xxx" /> (if I understa...

Is it possible to have a List<string> as a property on an active record class

Is it possible to have a HasMany relationship of a basic type such as String, on an ActiveRecord class, without the need for creating another entity such as (TodoListItem) to hold the value. [ActiveRecord] public class TodoList { [PrimaryKey] public int Id { get { return _id; } set { _id = value; } } [HasMany(typeof(...

How do you execute a stored procedure using Castle ActiveRecord?

I believe there is a discussion on this very topic somewhere on the net but I lost the url and I am unable to find it via googling. What I might try right now would be: ISessionFactoryHolder factoryHolder = ActiveRecordMediator<EntityClass>.GetSessionFactoryHolder(); ISession session = factoryHolder.CreateSession(typeof(EntityClass)); ...

Generate a default CRUD UI when using Castle ActiveRecord (.net)

Is there any simple way to generate a default crud (given an entity) with activerecord (castle implementation) or something similar for NET? There is something like this for RoR ( it think its called activescaffold) Thanks ...

Can I tell the Table Name of an ActiveRecord class in c#?

I'm trying to verify if a schema matches the objects I'm initializing. Is there a way to get the TableName of a class other than simply reflecting the class name? I am using some class with explicit TableNames Edit: using Joe's solution I added the case where you don't specify the table name, it could probably use a constraint public...

NHibernate/ActiveRecord - Any way to map to a foreign key column only?

I'm using Castle ActiveRecord, but this question applies to NHibernate, too, since a solution that works with NHibernate should work for ActiveRecord. Anyway, what I have is an underlying table structure like this: TableA -hasMany-> TableB I have corresponding objects EntityA and EntityB. EntityA has an IList of EntityB objects. Thi...

Can I flush my NHibernate session and get a new session without committing the transaction?

I'm using Castle ActiveRecord for persistence, and I'm trying to write a base class for my persistence tests which will do the following: Open a transaction for each test case and roll it back at the end of the test case, so that I get a clean DB for each test case without me having to rebuild the schema for each test case. Provide the...

How can I preload records with parent-child self-references using Castle ActiveRecord?

My SQL table looks like this: CREATE TABLE Page ( Id int primary key, ParentId int, -- refers to Page.Id Title varchar(255), Content ntext ) and maps to the following class in my ActiveRecord model: [ActiveRecord] public class Page { [PrimaryKey] public int Id { get; set; } [BelongsTo("Parent")] publ...

Active Record / Three Tier Architecture

I would like to separate my application into three tiers to use a service layer. I would also like to use the same domain model in both the UI tier, and the business layer tier because I control both ends. This makes sense, but I would also like to use Castles Active Record for the Data Access layer. Because of this I can not longer ref...

Custom query with Castle ActiveRecord

I'm trying to figure out how to execute a custom query with Castle ActiveRecord. I was able to run simple query that returns my entity, but what I really need is the query like that below (with custom field set): select count(1) as cnt, data from workstationevent where serverdatetime >= :minDate and serverdatetime < :maxDate and userI...

What automatic code generation tools are available for Castle ActiveRecord classes?

If I have an existing database, I want to be able to automatically code generate the corresponding Castle ActiveRecord C# classes based on the db schema. My primary intent is to avoid manually creating each class. What are my options for code gen tools with templates that can already specifically do this for Castle ActiveRecord? (Note:...

How to prevent writing object changes to the database on Flush with Castle ActiveRecord / NHibernate

The default behavior of NHibernate is the write all changes to objects to the database when Session.Flush() is called. It does this whether you want it to or not. How do we prevent writing bad data to the database when we need to do things like validate business rules or input? For instance .. Customer Name is not null. User opens ...

Castle/ Active Records: How do you count objects?

Hi, I'm trying to do a simple "Select Count(*) from PRODUCTS where date > xxx" with Castle on NHibernate. If I was directly using NHibernate, I could reuse this question answers but unfortunately I see no easy way to access the Current NHibernate session from Castle Records. I obviously don't want to retrieve all my objects and do a C...

which open source project(s) uses the castle activerecord?

Rather than the demos can you suggest any open source projects using castle activerecord for code study? ...

Are ActiveRecord/nHibernate SQL generation "safe"?

I'm doing this system Stacked and I am creating the search function. And in that process it occurs to me that maybe AR/nHibernate Expression.Like (and siblings) might maybe not be 100% "safe" in that you can create stuff like; "\r\ndrop database xxx;---" and similar things...? I would expect them to be safe, but I am not sure... ...

ActiveRecord/NHibernate: handling Lazy collections in a persistence-unaware context

My web application (MonoRail, Windsor, ActiveRecord) has a Startable import service and one or more Startable import readers. When, for example, a file is dropped in a directory, a reader parses the file, passes the data to the service, which updates and/or creates objects through repositories. The problem I have is that these Startable ...

Castle ActiveRecord - Determining connectionstrings during runtime

When using Castle ActiveRecord, is it possible to determine during runtime which connection string to use? As I understand it, ActiveRecord has to be initialized only once during the application's lifetime and this means that database connection strings have to be configured prior to initialization. However, is it still possible to det...

Get Row Count InvalidCast Exception from ScalarQuery

ScalarQuery<int> query = new ScalarQuery<int>(typeof(Role), "select count(role.RoleId) from Role as role"); return query.Execute(); It fails with the invalidcast exception but succeeds when count is replaced with max. ...