SmileTable Architecture – Application entities

Yes, I am still here.. It’s been a long time since my last post, I know.. but I am still in a game.

Okey, let’s back to SmileTable, let’s talk about what i have done in last 3 weeks

SmileTable Entities

I spent some time to think about what entities I need in my application. Of course SmileTable will be application designed for publish posts so It is clear that I need Post entity. I think It will be nice users have option to comment posts because It makes possibility to talk with other users and express feelings. That is why I have created Comment entity. Who will write posts and comments? ahh of course Users. And SmileTable is richer about User Entity. For basic start my application i need just one more entity which is RatePost. RatePost entity will allow users to rate posts. That is important because users will have option to sort posts by rate to see the most beautifull posts which bring the smile to somebody face!!!

So for now we have four entities:
– Post
– Comment
– User
– RatePost

We have entities and what now ? We also have to create connections between tables which are represent our created entities.

SmileTable Tables connections


We can see that one User can write many Posts, can Rate many Posts and can write many Comments. We also see that one Post can have many Rates and many Comments.

I don’t think this is optimum solution but I think that It will works in SmileTable application. We will see 🙂

Of course my ERD is without all necessery properties to SmileTable application. It’s kind of draft how It will works.

What You can see on the picture above is some kind of ERD generated by Visual Studio plug – EFPowerTools. You may ask what does EF mean. EF is acronim from Entity Framework which is great ORM. And ORM in simple words is just a tool for translate c# code to sql .


In smile Table application I am using EF and code-first approach. That is mean that I am creating entities which are just a simple classes with properties and EF map it to tables.

You wonder what about connections between tables, You don’t have to worry about It. EF is very inteligent tool and create that connections for You, You just need to point that connections in Entities. In ERD picture You can see Navigation Properties section. For Post Entity example we can see Comments and User properties and in Properties UserId property which is Foreign Key for User Navigation Property.

Let’s look at that class. How It looks like in c#

public class Post
public int PostId { get; set; }
public string Title { get; set; }
public string Message { get; set; }

public virtual User User { get; set; }
public int UserId { get; set; }

public virtual ICollection<Comment> Comments { get; set; }

You see that we have navigation properties: User and Comments and we also have explicitly declared ForeignKey by attribute and Table name by Table attribute. It is no neccessery to use that because EF knows it 🙂

Basically we have two options we can use Data Annotations which I am using or we can use Fluent API. It’s better to use Fluent API in some cases but I like Data Annotations more 😉

For the end I just want to say that EF is a great ORM with many options like Migrations, configurations methods like OnModelCreating etc.
I meet with many opinions that Nhibernate is better than EF but for now I never use Nhibernate, and for now I haven’t had any trouble with EntityFramework,and I liked It so much 🙂




Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:


Komentujesz korzystając z konta Wyloguj / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Wyloguj / Zmień )

Zdjęcie na Facebooku

Komentujesz korzystając z konta Facebook. Wyloguj / Zmień )

Zdjęcie na Google+

Komentujesz korzystając z konta Google+. Wyloguj / Zmień )

Connecting to %s