DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Generating a LINQ to SQL DataContext for VS Express for Windows Phone

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

Erik Ejlskov Jensen user avatar by
Erik Ejlskov Jensen
·
Jan. 29, 12 · Mobile Zone · Interview
Like (0)
Save
Tweet
5.53K Views

Join the DZone community and get the full member experience.

Join For Free

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

Windows Phone Express Virtual screening sql

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • MACH Architecture Explained
  • Implementing Microservices Architectures
  • Testing Your Infrastructure as Code Using Terratest
  • C++ Creator Bjarne Stroustrup Interview

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo