Where is my connectionstring stored in a class library? - visual-studio-2010

I've just generated some EF models from my EDMX designer in a class library. I chose to create a new connection string because the one that I defined in my app.config wasn't picked up. So Visual Studio (i guess) created a new connection string for me called: pc-name.db-name.dbo (see screenshot).
However I can't seem to find where this connectionstring is stored, it sure isn't in my app.config.. But where is it?

Found it!

Related

L2S DBML Table Stuck as "Internal" Visual Studio

I have a Linq to SQL data context with several tables. One particular table is marked in the DBML designer as having Public access, however when I save and compile the assembly it always changes the access modifier in the .designer file to internal. Thus the build always fails (as I have classes in other assemblies that reference this table) and I have to go into the .designer file and change the internal modifier back to public. Any change to the DBML file at all causes this to happen, even if I specifically set the property in the designer (toggle it back and forth, whatever). Is this a bug in VS (problem experienced in VS2010 and VS2013) and is there a fix?
Thanks.
I believe I have finally found a solution:
Open the .dbml file outside Visual Studio (e.g. Notepad)
Locate the problematic table definition.
Change AccessModifier="Internal" to AccessModifier="Public"
Save and close the .dbml file
Update the table definitions in the .designer.cs file with the public modifier if you have not already done so.
In theory the dbml designer should be doing this for me when I change that property on the table but unfortunately it doesn't for these particular tables. Following these steps fixed the problem.

How to add a reference to another project in my solution through Visual Studio automation

I create a new solution and add some projects to it via the Solution2.AddFromTemplate. Now before I can build my solution successfully, I need to add a project reference from one of the projects to the other. I'm trying to navigate the VS automation object model, but cannot find how to do this.
I realize that I could just open the csproj as XML and change it on disk (as suggested here), but then I need to handle Visual Studio detecting the project file changing and prompting to reload it.
Anyone know how to do this or point me in the right direction?
Found the answer, posting for future reference.
The trick is to cast the Object property of the EnvDTE.Project to VSProject and then call AddProject on its References property.
var targetProject = (VSProject) _project.Object;
targetProject.References.AddProject(sourceProject);

How do I recover an Entity Framework 4 EDMX file when Visual Studio 2010 will not open it?

I have been following the examples from Chapter 2 in an early access edition of Entity Framework 4 in Action whereby one creates a database schema, generates an entity model from the database schema, and then performs some entity customizations with regards to object inheritance, adding complex properties, etc. Everything was great until I closed and then restarted Visual Studio 2010 SP1. After restarting, I can no longer open the EDMX file with the designer. I get a dialog box stating "Cannot load 'C:\Projects\Test\Test.MyModel\Model.edmx': An item with the same key has already been added.". There is no further information in the Output window.
How might one might recover the file?
How might one debug the model loading process to find a little more information on what "item" is attempting to load or even what type of "item" it is?
It's an XML file so you can open it up in text mode and see what the problem is. Sounds like there could be items with duplicate names somehow.

How to associate a Resx file to a class in Visual Studio 2010

How do I associate/"bind" an resx file to a class file in Visual Studio?
For example, when a new windows form is created, an resx file is automatically associated with it.
I am asking this as the following code doesn't open the right resource file for another .cs file I have:
ComponentResourceManager manager = new ComponentResourceManager(typeof(MyClass));
This code works fine for frmLogin from above however.
The MSDN documentation for the constructor:
Creates a ComponentResourceManager
that looks up resources in satellite
assemblies based on information from
the specified Type.
That a form has an associated .resx file is an implementation detail that's specific to forms. You cannot otherwise associate an arbitrary class with a .resx file. I assume that you actually want to use a ResourceManager here.
Do note that there's one already built-in through Properties.Resources, giving you access to resources that you added to Project + Properties, Resources tab.
Should you have lost this indenting by adding existing files to a project, you can restore the indenting for files, though I have not tried it for all file types, by using the 'DependentUpon' node in the project file.
The technique is described in more detail at Code rant: Nested files with 'DependentUpon' in Visual Studio
I found an existing answer on SO since discovering the article above, but as the question is formulated so differently I'm keeping this answer in place.

VS2010 RC: Add new domain service class wizard entities list is empty

Greetings!
I am going through Brad Abrams' SL4 + RIA Services series. Right now I am here:
http://blogs.msdn.com/brada/archive/2010/03/15/silverlight-4-ria-services-ready-for-business-exposing-data-from-entity-framework.aspx.
When I get to the "add domain service" step and the wizard asks you what entities you want to expose, the list is empty. The dropdown that let's me choose my Entity data context is there and the "DishViewEntities" is selected but it is not showing the "Restaurant" and "Plate" entities in the list below like it does in the picture.
I found this thread here:
http://forums.silverlight.net/forums/t/168724.aspx.
The poster has the same problem as me. I have restarted VS, rebooted, regenerated the EDMX, tried creating it in different folders. Still the list is empty. When it is empty, it will not allow me to select individual entities or generate the class.
Any ideas from the community? Thanks!
I had the same problem. I looked for answers on web, they all seemed to relate to installing the RiaServicesToolkit, or other packages, or the dbml confirguration string. But I noticed that when I was opening my Linq2Sql (dbml) in visual studio that I was getting a message about the configuration string missing or incorrect.
It turns out that the configuration string problem was the result of my SQL Server Agent being set to Manual instead of Automatic in my Services (Control Panel). Once I corrected this, the configurations string problem went away.
I don't know if that is also what was causing my RIA (Linq2SQL) problem (although I do see how it could), but after fixing this, and cleaning & rebuilding the solution, my Linq2SQL context appeared on the drop down list of the DomainService wizard and all was golden.
Hope this helps.
This happens from time to time in my project. I don't really have to create a new project (which would be very unfeasable.) I usually make sure the project builds (clean/rebuild) and right-click on edmx file and do run custom tool. And make sure that no errors are being reported on Error and/or Output windows.
We solved our problem. Sometimes EDMX designer can't map Entities and tables. Right click each entity and select table mapping then ensure if all of your entities are mapped correctly.
When you want to add Domain Service Class an exception occur but (I don't know why) the exception message doesn't display. Than the list is seen empty.
If all of your mappings and web.config settings are right after rebuild progress domain service class addition works fine!

Resources