Now *Tuna Toksoz (@TehLike <http://twitter.com/TehLike> on twitter)* solved
it for me, by referencing
http://ayende.com/Blog/archive/2006/12/26/LocalizingNHibernateContextualParameters.aspx
Lots of thanks to him of course.

For TotalLikes:
Map(artiicle => artiicle.TotalLikes).Formula(
               @"( (Select Count('') from ArticleUserLikes Where
ArticleUserLikes.Type = 1 AND ArticleUserLikes.Article_Id = Article_Id) )");

For TotalDislikes:
Map(artiicle => artiicle.TotalLikes).Formula(
               @"( (Select Count('') from ArticleUserLikes Where
ArticleUserLikes.Type = 0 AND ArticleUserLikes.Article_Id = Article_Id) )");

The reason I'm using "1" and "0" above is that, as per my understanding, the
formula is part of SQL statement, and I'm using MS SQL as DB, where boolean
is bit (0/1).


*Thanks a lot again, Tuna.*

Regards,

--
Mohamed Meligy
Information Analyst (.Net Technologies) – Applications Delivery - TDG
Injazat Data Systems
P.O. Box: 8230 Abu Dhabi, UAE.

Phone:  +971 2 6992700
Direct:   +971 2 4045385
Mobile:  +971 50 2623624, +971 55 2017 621

E-mail: [email protected]
Weblog: http://weblogs.asp.net/meligy


On Thu, Oct 29, 2009 at 3:11 AM, Mohamed Meligy <[email protected]>wrote:

> Let's say we have schema like this (simplified):
>
> Article
> {
>     Article_Id (PK, int)
>      Title (string)
> }
>
> User
> {
>     User_Id (PK, int)
>     Username (string)
> }
>
> ArticleUserLikes
> {
>     User_Id (Composite PK Part, int)
>     Article_Id (Composite PK Part, int)
>     *Like (boolean)*
> }
>
> Lets say I want the Article class to look like:
>
> public class Article
>> {
>>     public virtual int Id {get; private set;}
>>     public virtual int Title {get;set;}
>>
>> *    public **virtual **int TotalLikes {get;** **private **set;}
>>     public **virtual **int TotalDislikes {get; **private **set;}*
>> }
>>
>
> Where *TotalLikes *for Article with Id = 1 is soemthing like:
>
> *SELECT COUNT(Like) FROM ArticleUserLikes WHERE Article_Id = 1 AND Like =
> TRUE*
>
> And *TotalDislikes *for Article with Id = 1 is soemthing like:
>
> *SELECT COUNT(Like) FROM ArticleUserLikes WHERE Article_Id = 1 AND Like =
> FALSE*
>
>
> *How can I map TotalLikes and TotalDislikes ?*
>
>
> Regards,
>
> --
> Mohamed Meligy
> Information Analyst (.Net Technologies) – Applications Delivery - TDG
> Injazat Data Systems
> P.O. Box: 8230 Abu Dhabi, UAE.
>
> Phone:  +971 2 6992700
> Direct:   +971 2 4045385
> Mobile:  +971 50 2623624, +971 55 2017 621
>
> E-mail: [email protected]
> Weblog: http://weblogs.asp.net/meligy
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to