I need a guidance which mapping strategy to use - nhibernate

I am writing a process for sending email notification. Currently I write the email notifications in a table with the following columns:
email_notification_id => PK
notification_id => the notification
sender_id => User or Group object
recipient_id => User or Group object
sender and recipient can be of type User or Group. Obviously at the moment I cannot have FKs for sender or recipient.
1) The first option is to use Any in the mapping and add two additional columns for the type.
2) The second option is to create 4 classes for each combination and map them using discriminator:
class1 => sender of type Group, recipient of type Group
class2 => sender of type Group, recipient of type User
class3 => sender of type User, recipient of type Group
class4 => sender of type User, recipient of type User
3) Other options?
What do you think about this?
Best Regards

If it were me and I had control over the database I would change the two columns sender_id and recipient_id to sender and recipients. These would be string fields that contain the raw email addresses you are intending to use.
This is just another way to do it. Not necessarily the best as far as database design is concerned but simple from an implementation and mapping perspective.

you could also create a EmailEntityBase (or whatever better phrasing you may find) class, from which both Group and User will inherit.
then your Notification entity would refer to EmailEntityBase sender and recipient properties.

Related

Private and shared address book with LDAP?

For a set of users belonging to some organisation, I want to provide the following:
each user should have a private address book
each user should have access to a company address book
I wonder how to model this scenario in LDAP so that:
user connects to LDAP server with some client
user performs a search for some string
all matching entries from the global address book are returned
all matching entries from the user's private address book are returned
Is searching the global and private address book possible with a single query? I guess the user would provide his path in LDAP as DN, but the global address book would be located at a different DN. I imagine something like that:
/
/OU=private-address-books
/CN=user1
/CN=entry1
...
/OU=global-address-book
/CN=entryABC
So is it possible to somehow automatically reference the global address book under the user's private address book?
You would probably be best off to arrange your DIT Structure to be more like:
ou=private,ou=Addressbooks...
ou=public,ou=Addressbooks...
You then could search using the the ou=addressbooks as the baseDN.
Or better, assign an Attribute boolean type private=TRUE to each entry.
So for all addressbooks,
(objectClass=Entry)
And for private
(&(objectClass=Entry)(private=TRUE))
And then finally, you may be able to use an ExtensibleMatch search filter to search both containers.
-jim

EF Table with multiple references to same Table

I have a Database First Entity Framework Model
Tables:
1) User
Id
2) Article:
Id
UserCreated > Ref to User last edited User
UserChanged > Ref to User which created the Article
Enity Framework is Generating a Model like this
Partial Public Class Article
Public Property ID As Integer
Public Property UserCreated As Integer
Public Property UserChanged As Integer
Public Overridable Property User As User
Public Overridable Property User1 As User
End Class
Now I have another table like Vouchers also with UserCreated and UserChanged but names User1 and User.
Is there any way to specific the name of the property without changing the class itself because its generated from the Database.
You can use a DataAnnotation on the UserCreated property to specify the foreign key name:
[ForeignKey("UserCreated")]
http://msdn.microsoft.com/en-gb/data/gg193958.aspx
You can easily change the property name for User1 to any other name using the edmx-Designer.
But you should be aware that User is the reference to the column UserCreated. Because it may be that User references to UserChanged. You should check that. The best way is to check the name of the relationship. Therefore you need to give the relationship a meaningful name that you are able to distinguish them. Then you can right click on the relationship line and retrieve the relationship name.

Private Messaging(User A to User B)

I am trying to create a part of my app which allows users to message one another. The messages will only be one-to-one PM. I'm using Parse as the backend. Any suggestions?
You need to have an associative table ( create it from your Parse.com website account ) that should contains the pointer to the sender User, the pointer to the Receiver User and the message to send. So:
let's call the table class you need as "UsersChat"
objectId (string) default parse field
senderUser (Pointer:User) pointer to the user who send the message
receiverUser (Pointer:User) pointer to the user who will receive the message
message (string) concrete message to send
createdAt (Date) default parse field that contains the creation row, so the sent message date/time we can say
updatedAt (Date) default parse field
ACL (ACL) default parse field

Filtering with CollectionViewSource in MVVM/XAML in Silverlight

I have 4 tables:
Stores => StoreID , AddressID
Contacts => ContactID, StoreID, DesignationID,
Designation => DesignationID
Address => AddressID
In Entity Query I used Include while getting all the details of the stores.
ObjectContext.Stores.Include("Address").Include("Contacts.Designation");
So I got all the stores with all their contacts and other objects like Address. Now I want to filter Store's contacts but our Domain Service Linq does not allow filtering with Include. It include all the data. So I want to use CollectionViewSource for filtering my child data.
In UI, I have One ListBox for Store Information and within that ListBox -> I have one more list box for store's Contacts and I want this Contacts to be filtered with some condition on its Load...
I can't figure out how to do this with MVVM or directly in XAML. But Doing it with MVVM is preferably better.
Can anyone please help me solving this problem?
Thanks for your time and help.
You need to first get hold of the default ICollectionView for your source item.
You can do this like so
var collectionView = CollectionViewSource.GetDefaultView(collectionToFilter);
Next, you create a filter delegate like so
collectionView.Filter = delegate(object item){return some boolean expression;};
Hope this helps

NHibernate mapping message logic

I made some classes that represents my messages logic:
Message - representation of THE message :)
MessageBoxBase - base class for all 3 kind of messagebox
MessageInbox - representing inbox
MessageOutbox - representing outbox
MessageCustombox - user defined message box
MessageBoxItem - message item in any messagebox with such data as IsReaded etc.
MessageBoxCollection - Collection of messageboxes - Inbox, Outbox and List of CustomBoxes - only that 3 properties.
Finally in my agregate root User have MessageboxCollection, and I can use it somewhat like that:
myUser.MessageBoxes.Inbox.Add(...)
myUser.MessageBoxes.Outbox.Items....
I dont have any DB structure right now and I'm open on sugestion, but I was thinking about something like that:
MessageInInbox - UserId,MessageId, IsReaded etc.
MessageInOutBox - Same as in Inbox
MessageInCustomBox - UserId,MessageId, CustomBoxId and so on
CustomBox - BoxId, UserId, BoxName etc.
Message - plain message row, subject, content, author etc.
One I'm sure is that I don't want to create in DB row for each Inbox/Outbox for each user like it is in CustomBox case (something like unnecessary dictionary for inboxes and outboxes per user).
And in that point I have a problem - how the hell to map that ? :)
Have any suggestions? Maybe my domain is crappy? I'm waiting for yours response :)
There is a more simple solution that is that you only have two database tables called messages and boxes.
Messages - (Id, IsRead, Subject, Message, Sender, UserId, BoxId)
Boxes - (Id, Name, UserId)
This solution now allows a user to have several custom boxes and he should always have the defaults created for him. And the Object model can be User has a list of Boxes and each box has a list of messages.