Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does LINQ to SQL use the ActiveRecord Pattern?

I've just been researching the ActiveRecord pattern, and based on this (http://en.wikipedia.org/wiki/Active_record_pattern), it seems Linq 2 Sql more or less implements this, am I wrong? or what would need to be changed for it to conform to the ActiveRecord pattern?

like image 537
GONeale Avatar asked Oct 27 '25 15:10

GONeale


1 Answers

In some ways it can feel like an active record pattern, but it really isn't. Basic example:

//load the entity
var c = myDataContext.Customers.FirstOrDefault(c => c.Id == 1876);
c.Name = "George Armstrong Custer";
 // saves the entity 
myDataContext.SubmitChanges();

Active record

//load the entity
var c = Customer.GetCustomer(9);
c.Name = "Varus";
//save the entity
c.Save();

Active record really just involves one class which covers the model and supplies the data interface Linq to Sql follows a different path where there are a few model classes and a separate data interface, otherwise known as a repository.

PS: For a good example of an ORM that uses the active record pattern, check out Subsonic.

like image 195
Wyatt Barnett Avatar answered Oct 29 '25 05:10

Wyatt Barnett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!