Hi Igork,
This is my way to solve the lack-of-mixin problem in C#. I am developing a web application.
I have interfaces like IFileAttachable, ICommentable, ITaggable.
All the interfaces have no member.
If the current object is ICommentable, my controller will automatically use ICommentService to load the comment from db. like this:
Code:
public ICollection<Comment> GetComments(ICommentable obj)
{
Type objType = obj.GetType();
return repository.FindAll(Where.Comment.ObjectId == obj.Id
&& Where.Comment.objectTypeString == objType.AssemblyQualifiedName
&& Where.Comment.AddOrder(OrderBy.Comment.CreatedOn.Asc)
);
}
Then a comment section will be rendered automatically if the current object is ICommentable.
So in db side, my comments table is not associated with any other classes. I have to load/save comments basing on the current object. Before, I have this work perfectly if I map the Type directly. I changed to nhibernate trunk version and now have to convert the Type to its AssemblyQualifiedName by myself. Something strange.
IgorK wrote:
Hi cloudster!
What would you store in DB for this "type" and what is more interesting - for objectId?
Are you really want to create association from this class to EVERY other possible persistent class? But then I believe you have to create some sort of common interface, or even common (abstract) base class for every other persistent class in whole application - to map ObjectId to this class/interface... And of course you have to use one common sequence of values for ids - uuid for example.