Mobile Zone is brought to you in partnership with:

Erik Ejlskov Jensen is a .NET Data Developer, and SQL Server Compact MVP. He is also the author of a number of tools for SQL Server Compact. He has been working in IT for too many years, and enjoy blogging (http://erikej.blogspot.com) and tweeting (@ErikEJ) Data Development related news and tips. Erik Ejlskov is a DZone MVB and is not an employee of DZone and has posted 58 posts at DZone. You can read more from them at their website. View Full User Profile

Generating a LINQ to SQL DataContext for VS Express for Windows Phone

01.29.2012
| 4072 views |
  • submit to reddit

As you may know, you can generate a Windows Phone DataContext based on an existing database for use with Windows Phone Mango “Local Database”, as described here and here. But this feature is only available if you own a paid Visual Studio edition (Pro or higher), as the Express editions do not support add-ins.

But users of Visual Studio 2010 Express for Windows Phone can now also take advantage of all the productivity benefits of the “Database First” approach to Local Database development on Windows Phone.

Provided you have a SQL Server Compact Database ready, designed according to the guidelines here, and possibly created by using a tool, you can follow this simple procedure to generate and add the DataContext to your Windows Phone solution.

Anyone using the Express tools will notice that SQLMetal (which is used behind the scenes to create the DataContext file) is not included. You can get it from the Microsoft SDK bundle http://www.microsoft.com/download/en/details.aspx?id=8279. You only need to choose the following options to get the required files.

image

Then go to the download page for my ExportSqlCe tool, and download the latest version of the Exportsqlce.exe command line utility.

You can now generate a DataContext file from the command line, as documented here.

In this example, I will generate a DataContext based on the Chinook sample database.

exportsqlce wpdc "Data Source=C:\projects\Chinook\Chinook.sdf" C:\temp\Chinook.cs

Notice that the format of the database must be SQL Server Compact 3.5.

In Visual Studio, open your Windows Mango project, and from Solution Explorer, select Add, Existing Item, and browse to the file the was just created.

image

Remember to add a reference to System.Data.Linq to your project.

image

You can now start using the generated DataContext in your project!

<span style="color: blue">using </span>(ChinookContext db = <span style="color: blue">new </span>ChinookContext(ChinookContext.ConnectionString))
{
    db.LogDebug = <span style="color: blue">true</span>;

    <span style="color: blue">var </span>artist = db.Artists.FirstOrDefault();
    artist.Name = <span style="color: #2b91af">Guid</span>.NewGuid().ToString();

    db.SubmitChanges();
}

Happy coding…

Source: http://erikej.blogspot.com/2012/01/generating-linq-to-sql-datacontext-with.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+ErikejBlogsAboutSqlCompactnetAndRelatedStuff+%28Everything+SQL+Server+Compact%29&utm_content=Google+Reader

Published at DZone with permission of Erik Ejlskov Jensen, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Lucie Hauri replied on Mon, 2012/03/26 - 4:45am

Finally I understand how to do it. I will try to generate it on my smart phone. yacht charter lefkas

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.