小编Gre*_*reg的帖子

如何在ASP.NET中的响应流中添加编码信息?

我有以下代码:

public void ProcessRequest (HttpContext context) 
{
    context.Response.ContentType = "text/rtf; charset=UTF-8";
    context.Response.Charset = "UTF-8";
    context.Response.ContentEncoding = System.Text.Encoding.UTF8;
    context.Response.AddHeader("Content-disposition", "attachment;filename=lista_obecnosci.csv");
    context.Response.Write("??????ó????????Ó?");
}
Run Code Online (Sandbox Code Playgroud)

当我尝试打开生成的csv文件时,我得到以下行为:

  • 在Notepad2中 - 一切都很好.
  • 在Word中 - 转换向导打开并要求转换文本.它建议UTF-8,这在某种程度上是好的.
  • 在Excel中 - 我变得非常混乱.这些波兰语字符都不能显示.

我想在我的字符串前写下那些特殊的编码信息字符,即

context.Response.Write((char)0xef);
context.Response.Write((char)0xbb);
context.Response.Write((char)0xbf);
Run Code Online (Sandbox Code Playgroud)

但那不会有任何好处.响应流将其视为普通数据并将其转换为不同的数据.

我很感激这方面的帮助.

asp.net encoding response response.write

14
推荐指数
2
解决办法
3万
查看次数

nhibernate多对多映射 - 映射表中的附加列?

我有以下映射定义:

  <class name="Role" table="Role" optimistic-lock="version" >

    <id name="Id" type="Int32" unsaved-value="0" >
      <generator class="native" />
    </id>

    <property name="RoleName" type="String(40)" not-null="true" />

    <bag name="UsersInRole" generic="true" lazy="true" cascade="all" table="UserRoles" >
      <key  column="RoleId" />
      <many-to-many column="UserId" class="SystemUser, Domain"/>
    </bag>
Run Code Online (Sandbox Code Playgroud)

<id name="Id" type="Int32" unsaved-value="0" >
  <generator class="native" />
</id>
<property name="UserName" type="String(40)" not-null="true" unique="true" />
Run Code Online (Sandbox Code Playgroud)

此映射生成映射表UserRoles,它有两列 - RoleId和UserId.

但是,我想为该关系添加额外的属性 - 即一些枚举值定义关系的状态以及有效的开始和结束日期.

是否可以在nhibernate中执行或者我是否需要在此处添加其他类并将关系m-to-m更改为2个关系[user] 1-to-m [user_role] m-to-1 [role]?

nhibernate nhibernate-mapping

11
推荐指数
1
解决办法
6262
查看次数

删除抛出"已删除的对象将通过级联重新保存"

我有以下型号:

<class name="Person" table="Person" optimistic-lock="version">
  <id name="Id" type="Int32" unsaved-value="0">
    <generator class="native" />
  </id>
  <!-- plus some properties here -->
</class>

<class name="Event" table="Event" optimistic-lock="version">
  <id name="Id" type="Int32" unsaved-value="0">
    <generator class="native" />
  </id>
  <!-- plus some properties here -->
</class>

<class name="PersonEventRegistration" table="PersonEventRegistration" optimistic-lock="version">
  <id name="Id" type="Int32" unsaved-value="0">
    <generator class="native" />
  </id>
  <property name="IsComplete" type="Boolean" not-null="true" />
  <property name="RegistrationDate" type="DateTime" not-null="true" />
  <many-to-one name="Person" class="Person" column="PersonId" foreign-key="FK_PersonEvent_PersonId" cascade="all-delete-orphan" />
  <many-to-one name="Event" class="Event" column="EventId" foreign-key="FK_PersonEvent_EventId" cascade="all-delete-orphan" />
</class>
Run Code Online (Sandbox Code Playgroud)

在Person和Event中都没有指向PersonEventRegistration的属性.

当我尝试从PersonEventRegistration中删除条目时,出现以下错误:

"deleted object …
Run Code Online (Sandbox Code Playgroud)

c# nhibernate cascade nhibernate-mapping

6
推荐指数
1
解决办法
9401
查看次数