Given this diagram:
Linq to SQL
Models are generated in singular. A table with Persons, gets represented as a class “Person”.
The Many to Many table PersonContactInfo, gets also generated as a Class. Also, the ContactInfo class, has a ContactInfo1 property, (apparently a class and a property cant have the same name?).
Accessing the list from code looks something like this:
LTSModelDataContext lts = new LTSModelDataContext();
List<Person> listPersons = lts.Persons.ToList();
Accessing the contact information for a person would look like this:
Person p = new Person();
var a = p.PersonContactInfos[0].ContactInfo.ContactInfo1;
Linq to Entities:
Models names are generated as they are in the DB, so table Persons, gets created as a class Persons.
The model doesn’t create the PersonContactInfo table it adds a Navigation Property (a more OOP approach, rather than a Relational approach).
Accessing the list from code looks something like this:
LTEEntities lte = new LTEEntities();
List <Persons> listPersons = lte.Persons.ToList();
Accessing the contact information for a person would look like this:
Persons p = new Persons();
var a = p.ContactInfos.First().ContactInfo;
Conclusions
Linq to SQL made a more comprehensive set of models from the DB, realizing the table names are plural and that a Class is singular is very neat. But the addition of the PersonContactInfo table to the model and its use to access the contact information for a person seems too much.
Linq to Entities, created a “perfect” model from the DB (prefect OOP Model), and accessing the contact information for a Person is more intuitive, but unfortunately the generation of names is not as perfect as Linq to SQL.
Next, inserting, updating and deleting…
No comments:
Post a Comment