Saturday, August 20, 2011

Creating a LINQ TO SQL Model for a SQL CE Database

Right now, Visual Studio 2010 cannot create directly a .dbml model (LINQ to SQL) from .sdf file (SQL Server CE). If you try to create a model and drag & drop a table, Visual Studio will give you an error and say that this feature isn't supported.

By default, you cannot use a dbml model for a SQL Server CE database.

Still, the model can be created by using the application SqlMetal.

The application can be found in the directory (supposing that you have Windows installed on the C: partition).

[Windows x64] C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin
[Windows x86] C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bin

1)Open Command Prompt (Start->Run->enter cmd in textbox).
2)Once the console (Command Prompt) is opened, write:

SqlMetal /dbml:Database.dbml Database.sdf
Database.dbml must be replaced with the path to the location where you want to generate the dbml model.
Database.sdf must be replaced with the path to the location of the database (the sdf file).

3)The generated file will contain the database map (the database model). To use the model in Visual Studio, you must attach it to your current project.

1 comment:

  1. You can also create a DataContext using gui tools with my SQL Server Compact Toolbox add-in

    ReplyDelete

Got a question regarding something in the article? Leave me a comment and I will get back at you as soon as I can!

Related Posts Plugin for WordPress, Blogger...
Recommended Post Slide Out For Blogger