mercredi 12 août 2015

Creating database model

I am working on creating model of my database to c# code. I found following problem :

If I add business logic to my class in constructor or I will do private setter then my model will be unable to use with quering or retriving data from DB. Below its just example.

   class User 
    {
     Guid Id {public get; private set;}

     public User()
     {
        Id = GUID.newGuid();
     }
    }

Question : Are you using duplicated model (one with business logic and other one for ORM )?

public class UserEntity
{
   Guid Id {public get;public set;}
}

EDIT : I am working with Dapper as ORM now , so by "model will not be able to use for retriving data" I mean that

var response = database.Query<User>(" SELECT ALL ...")

doesnt make sene in case of logic in constructor.

Aucun commentaire:

Enregistrer un commentaire