Code-First Data Model Creation

,

Code-first is the recommended approach for creating your data model in Windows Phone. It involves writing your classes and then generating your database using metadata contained in those classes.

Until now I have never been a fan of code-first when building desktop and client/server applications, because I saw how it can lead to a lack of attention being paid to the database schema—to its structure, constraints, and indexes. Yet, applied wisely, code-first offers some key advantages. One such advantage is that you do not break the application by forgetting to propagate a schema change to other developers on your team, because all changes to the schema are done via code metadata.

The following list outlines the steps for creating a data model and generating a database using the code-first approach and LINQ to SQL:

1. Manually create POCO classes representing your domain entities.

2. Create a class deriving from DataContext, with properties within the class representing tables within the database.

3. When instantiating your DataContext, provide a connection string with the location of your database file in isolated storage. The DataContext creates a database with the relationships defined in your data model.

After the database is in place, you are able to interact with the DataContext and the entity objects using LINQ to SQL.

The following section looks at each of these steps in detail, during the creation of a sample Twitter timeline viewer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.98.120