Is It An Entity, Or Is It A Data Model?

by Jon Davis 13. October 2009 00:16

One of the big dilemmas I came across before making Gemli a publicly accessible resource (open source project) was what to call the objects being loaded and saved. I’d heard “entities” and I’d heard “data models”, and I didn’t know the difference.

Truth be told, I’m still not entirely sure I know the difference. But after Wikipedia searches and other small research I came to the conclusion that:

  • An “Entity” is a business object that is closer to being a domain object.
  • A “Data Model” is more of a description of something as it relates to data; it is closer to a database record, including its schema.

This distinction was important to me because Gemli is built to support POCO with minimal code, but it also needs to work with the data at a database integration level, so I needed to know what to call the two kinds of objects (the POCO object and the object that actually represents what will be loaded to/from the database). Initially, I called the objects that represented the database record “DataEntity”, and then its property that spit back out the POCO object was called the “InstanceObject” or something like that. Really weird. Bleaah.

Anyway, now any POCO object that is suitable for being wrapped and serialized to the database is called in Gemli an “Entity”. Once wrapped into database-translatable semantics, it is called a “Data Model”.

This is why some generic interfaces in Gemli take a TEntity and some take a TModel. They are not named differently because they are inconsistent, they are named differently because a different kind of type is expected. If you pass in a TEntity, you’re probably dealing with a generic interface that will spit that TEntity back out in its original form. If you pass in a TModel, you’re probably dealing with a query object or a data provider that can only work with data models using Gemli’s data modeling semantics.

var Bob = new Person("Bob Smith"); // Bob is an Entity. Person is any ol' POCO class.
var BobRecord = new DataModel<Person>(Bob); // BobRecord is a data model.
BobRecord.Save(); // Bob is a new customer/employee/thingamajig.

var SueRecord = DataModel<Person>.NewQuery()
    .WhereProperty["FirstName"].IsEqualTo("Sue")
    .SelectFirst(); // Sue has a record in the database because she is an
                    // existing employee (and yes lambdas will come to 
                    // Gemli, sheesh!)
Person Sue = SueRecord.Entity; // Sue is a person, too!!

Not sure if this discussion is valuable to anyone, but that’s Gemli’s story on the word choices.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading




 

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Jon Davis (aka "stimpy77") has been a programmer, developer, and consultant for web and Windows software solutions professionally since 1997, with experience ranging from OS and hardware support to DHTML programming to IIS/ASP web apps to Java network programming to Visual Basic applications to C# desktop apps.
 
Software in all forms is also his sole hobby, whether playing PC games or tinkering with programming them. "I was playing Defender on the Commodore 64," he reminisces, "when I decided at the age of 12 or so that I want to be a computer programmer when I grow up."

Jon was previously employed as a senior .NET developer at a very well-known Internet services company whom you're more likely than not to have directly done business with. However, this blog and all of jondavis.net have no affiliation with, and are not representative of, his former employer in any way.

Contact Me 


Tag cloud

Calendar

<<  October 2020  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar