Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio and LINQ: placing the DBML file in separate directory in the project

My strategy was to keep the project's layout clean. Given that this is a datalayer project, and I'll have a class file for each concerned entity, I thought I would put the .dbml into its own directory. It turns out that locating your .dbml file within a subdirectory turns it into a lower level namespace of sorts.

This is a C# class library project.

Any hints where I could turn this functionality off, and get access to the LinqToSql dbml datacontext name without having to type the directory name to get access to the actual LinqToSql classes?

like image 769
p.campbell Avatar asked May 07 '09 18:05

p.campbell


People also ask

How to create a DBML file in Visual Studio Code?

To create a DBML file, right-click on your project à Go to Add à select New Item à select LINQ to SQL template, give name as “ EmployeeDB ” and click like as shown below.

How to create a DBML file using LINQ?

To create a DBML file, right-click on your project à Go to Add à select New Item à select LINQ to SQL template, give name as “ EmployeeDB ” and click like as shown below. After adding LINQ to SQL dbml file, that will be as shown below. Here if you observe, we have two sections in the left side section.

How to use LINQ to SQL in your project?

Now we finished creating a new project. To use LINQ to SQL in our application, we need to create a “ DBML ” file, and the DBML file will contain source code that will allow us to write LINQ queries to get data from the SQL database.

How do I import a LINQ file into Visual Studio?

Open the O/R designer. To add a LINQ to SQL entity model to your project, choose Project > Add New Item, and then select LINQ to SQL Classes from the list of project items: Visual Studio creates a .dbml file and adds it to your solution. This is the XML mapping file and its related code files.


2 Answers

Turns out you need to find the properties of your DBML on the LinqToSql design canvas.

  • Right click -> Properties Find the Context Namespace.
  • Type in the namespace that you expect to have your DataContext classes available in.
  • Right below, find the Entity Namespace.
  • Do the same

Resharper Users: you have the option to view the properties of your DBML's subdirectory, and set the namespace attribute there.

like image 77
p.campbell Avatar answered Sep 21 '22 00:09

p.campbell


If you go to the directory in your solution and view the properties of that directory you will see the attribute: Namespace provider = true

Set this to false

You can then go update the namespace to match the root namespace in your DBML file. Now whenever you add new dbml files in there, it will keep the namespace based on the root folder.

like image 37
CodeLikeBeaker Avatar answered Sep 24 '22 00:09

CodeLikeBeaker