views:

260

answers:

3

Ok, so I want to create a code behind for non-aspx classes. I have mapping files (classes) that I want to show in project as a code behind for entites. Is there a way to do that in VS2008.

+1  A: 

you can create a designer file by naming it Class.Designer.(vb or cs) and it will show up as a code behind for whatever class you're creating. One of the classes will have to be a partial class, however.

Joseph
+1  A: 

It sounds like you're talking about files showing up as nested in Solution Explorer. ASP.NET Codebehind files are just one example of that.

What you want in the project file is something like this:

<ItemGroup>
    <EmbeddedResource Include="Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
</ItemGroup>
<ItemGroup>
    <Compile Include="Resources.Designer.cs">
      <DependentUpon>Resources.resx</DependentUpon>
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
    </Compile>
</ItemGroup>

I believe it's the <DependentUpon> element that indicates the nesting.

John Saunders
A: 

I actually got this to work. Now all "Map" show as code behind classes for my entities, saves me lot of time when looking up the Mapping for the entity. Here is how it looks in the project file.

<Compile Include="Entities\OrderMap.cs">
  <DependentUpon>Order.cs</DependentUpon>
</Compile>

We also created a template so that one can just right click, choose add NH entity and it gets saved to the project as shown above. Only problem right now is re-naming of the entity, one has to go in the project and manually change the name. But that does not happen that often and is a small trade off for gain in the productivity.

epitka