Using OpenAccess Forward Mapping really allows you to focus on building a strong model, rather than getting caught up in the persistence details, and this can expedite development time dramatically. Every developer I know could use a little more time to focus on more important things :) Before we can use the OpenAccess Forward Mapping Wizard, we need to create a model for our application. After we have a solid model, we can run the wizard, and it will create the database for us! Awesome!
I like setting it up this way for a few reasons:
1: 2: public abstract class PersistedEntity : IPerstistable
3: { 4: protected int id;
5: protected DateTime createdOn;
6: protected DateTime lastEditedOn;
7: 8: public int ID
9: { 10: get { return id; }
11: } 12: 13: public DateTime CreatedOn
14: { 15: get { return createdOn; }
16: set { createdOn = value; }
17: } 18: 19: public DateTime LastEditedOn
20: { 21: get { return lastEditedOn; }
22: set { lastEditedOn = value; }
23: } 24: } As you can see here, I have made the fields “protected” this is so that it can easily work with any inheritance structure i choose to use in OpenAccess.
This interface will set up the behavior regarding notes in the classes that implement it.
1: public interface INotable
2: { 3: IList<Note> Notes 4: { 5: get; 6: } 7: } Next, I need to create a way for my models to have alerts added to them.
1: public interface IAlertable : IPerstistable
2: { 3: IList<Alert> Alerts 4: { 5: get; 6: } 7: }
Here is what it looks like all put together:
I know those instructions were a little fast, so I urge you to go check out the great walkthrough on Telerik TV. You can find it here: Forward Mapping with Telerik OpenAccess ORM.
Once we have completed these steps OpenAccess will create a schema for us like the one shown below.
There are a few interesting things to note here:
I hope you enjoyed this blog, and I look forward to hearing any questions or comments.
Next time we will create a simple DAL which will allow our UI to access our data, so check back soon!