简体   繁体   English

流利的NHibernate类作为域类的代码

[英]Fluent NHibernate Classes as code behind for Domain classes

Ok, so I want to create a code behind for non-aspx classes. 好的,所以我想为非aspx类创建一个代码。 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. 有没有办法在VS2008中做到这一点。

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. 您可以通过将其命名为Class.Designer.vb或cs来创建设计器文件,该文件将以代码形式显示在您要创建的任何类中。 One of the classes will have to be a partial class, however. 但是,其中一个类必须是局部类。

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. ASP.NET Codebehind文件只是其中的一个示例。

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. 我相信是<DependentUpon>元素指示嵌套。

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. 我们还创建了一个模板,以便可以右键单击,选择添加NH实体,然后将其保存到项目中,如上所示。 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. 但这并不会经常发生,这是为提高生产率而付出的很小的代价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM