two questions

3 views
Skip to first unread message

Ivan Bolčina

unread,
Oct 18, 2010, 3:59:22 AM10/18/10
to castle-pro...@googlegroups.com

Hi.

 

Two questions:

1.       Is there a LINQ to Caste active record?

2.       What is the best way to write simple queries like »...where name like '%john%' and age>10«

Thanks

 

Ivan Bolčina
SOFTWARE DEVELOPMENT
MANAGER

ivan.b...@apida.si

tel: +386 51 680 415

 

www.apida.si

 

 

image001.png

Roelof Blom

unread,
Oct 18, 2010, 6:52:23 AM10/18/10
to castle-pro...@googlegroups.com
Inline

On Mon, Oct 18, 2010 at 9:59 AM, Ivan Bolčina <ivan.b...@apida.si> wrote:

Hi.

 

Two questions:

1.       Is there a LINQ to Caste active record?

Yes, use the extension methods in Castle.ActiveRecord.Framework.ActiveRecordLinq,
or derive from ActiveRecordLinqBase<T>

2.       What is the best way to write simple queries like »...where name like '%john%' and age>10«

use the PredicateBuilder class on the IQueryable supplied by ActiveRecord
 

Thanks

 

Ivan Bolčina
SOFTWARE DEVELOPMENT
MANAGER

ivan.b...@apida.si

tel: +386 51 680 415

 

www.apida.si

 

 

--
You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.

image001.png

Ivan Bolčina

unread,
Oct 19, 2010, 2:21:04 AM10/19/10
to castle-pro...@googlegroups.com

Wow, nice... How come I didn't find anything in documentation.

 

Also, is there fetch join in active record?

image001.png

Roelof Blom

unread,
Oct 19, 2010, 3:07:02 AM10/19/10
to castle-pro...@googlegroups.com
image001.png

Ivan Bolčina

unread,
Oct 20, 2010, 9:34:49 AM10/20/10
to castle-pro...@googlegroups.com

Hi.

 

Why isnt there a flag in relation like lazy but for eager loading?

image001.png

Markus Zywitza

unread,
Oct 20, 2010, 10:49:57 AM10/20/10
to castle-pro...@googlegroups.com
Because that's the default behaviour. If you do not specify lazyness, all entities referenced from a loaded entity are loaded directly after it. Lazyness is used to stop NH/AR from loading objects that are not needed.
 
-Markus
2010/10/20 Ivan Bolčina <ivan.b...@apida.si>
image001.png

Ivan Bolčina

unread,
Oct 20, 2010, 2:29:36 PM10/20/10
to castle-pro...@googlegroups.com

Sorry, I ment why is there not a simple way to do 1 query instead of N+1?

image001.png

Markus Zywitza

unread,
Oct 20, 2010, 3:28:52 PM10/20/10
to castle-pro...@googlegroups.com
It is not N+1, it is 2.

Assume you have Blog : Posts as 1 : n with a non-lazy posts collection.
If you load a blog, there are 2 queries - one for the blog and one for all posts.

N+1 occurs when you have 1 : n with a lazy collection and you are enumerating the collection. Then you have one query for the blog and n queries for n posts.

As a result, if your collection is not lazy, there is no N + 1. So the Eager=true flag would be only useful if you had a lazy collection, nullifying the laziness because of eager loading.

Eager loading is useful in the case you have a lazy collection but you know that you need to load all the referenced entities. Then you can specify in a query, that in this situation there should be no lazy loading, but getting all the childs at once.
image001.png

Ivan Bolčina

unread,
Oct 23, 2010, 9:55:05 AM10/23/10
to castle-pro...@googlegroups.com

Say, is there a way to specify this:

Blog : Posts

 

Load a blog by id, but leave posts empty. On save don't save posts.

 

But, if there is explicit call, lets say blog.LoadPosts(), then posts would be loaded and therefore a relation would be »normal«.

 

The reason is that I found that there are so many sqls executing – it is logical, because objects are in relation, but i would like to be more in control (n-tier situation). Lazy is not good for n-tier situations.

 

Right now I have this configured like this.

Blog has a array of posts(POSTS), but it is NOT attributesied as HasMany.

Post has a BLOG property, but it is also NOT attibutiesed as BelongsTo

 

When I need to send those to client, i manually fill necessary details.

 

But is there a way to run-time attributise an element, say array of posts in a blog, and then load it using this run-time attributisation?

 

Hope you understand this.

 

Br,ivan

image001.png

Markus Zywitza

unread,
Oct 26, 2010, 2:18:54 PM10/26/10
to castle-pro...@googlegroups.com
Lazy is perfect for n-tier situations, when you use DTOs and AutoMapper.

If you have a 2-tier (client/database) app, chances are good, that some collections are never needed, so laziness saves you from loading to much.

In a 3-tier app, you should use DTOs specialized for the query and AutoMapper to fill them. Then laziness is necessary to not load properties that are not mapped to the requested DTOs.

Sharing AR objects between server and client in a 3-tier app is not recommended at all, lazy or not.

-Markus

2010/10/23 Ivan Bolčina <ivan.b...@apida.si>
image001.png

Ivan Bolčina

unread,
Oct 27, 2010, 10:10:26 AM10/27/10
to castle-pro...@googlegroups.com

Hi.

I have written 3-tier application,where server loads/saves stuff, and for DTOs are used AR.

Since on client, I dont use save/load/etc, they act as simple POCO.

 

I think that whats great about AR is that there is no mapping, but having separate DTO is another form of mapping.

 

Where can I learn more about AutoMapper?

 

BR,ivan

image001.png

Patrick Steele

unread,
Oct 27, 2010, 10:23:16 AM10/27/10
to castle-pro...@googlegroups.com
image001.png
Reply all
Reply to author
Forward
0 new messages