简体   繁体   English

手动更改.dbml文件后如何更新数据模型类

[英]How to update data model class after manually changing .dbml file

Does anyone know how could I get the data model class updated after I make some custom changes in the .dbml file. 在.dbml文件中进行一些自定义更改后,没有人知道如何更新数据模型类。

I tried to manually mark some fields nullable in the .dbml, but changes are not visible in the code, no matter how many times I rebuild. 我试图手动将.dbml中的某些字段标记为可为空,但是无论重新构建多少次,更改都不会在代码中可见。 I even tried to edit .dbml(xml) in an external tool, and then save, but no use. 我什至尝试在外部工具中编辑.dbml(xml),然后保存,但没有用。

edit<< Here's the snippet for shaunmartin... 编辑<<这是shaunmartin的代码段...

<Table Name="dbo.Clients_Banks" Member="Clients_Banks">
<Type Name="Clients_Banks">
  <Column Name="ID" Type="System.Int32" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
  <Column Name="FKClients" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
  <Column Name="BankName" Type="System.String" DbType="NVarChar(100) NOT NULL" CanBeNull="false" />
  <Column Name="BankAccountNo" Type="System.String" DbType="NVarChar(50) NOT NULL" CanBeNull="false" />
  <Column Name="Party" Type="System.String" DbType="NVarChar(50)" CanBeNull="true" />
  <Column Name="ClientAccountNo" Type="System.String" DbType="NVarChar(50) NOT NULL" CanBeNull="false" />
  <Column Name="Active" Type="System.Boolean" DbType="Bit NOT NULL" CanBeNull="false" />
  <Column Name="NonResidentialAccount" Type="System.Boolean" CanBeNull="false" />
  <Column Name="Swift" Type="System.String" CanBeNull="true" />
  <Column Name="Iban" Type="System.String" CanBeNull="true" />
  <Association Name="Clients_Clients_Banks" Member="Clients" ThisKey="FKClients" OtherKey="ID" Type="Clients" IsForeignKey="true" />
</Type>

I just changed CanBeNull property from false, to true, for the last two members (Iban and Swift). 我只是将最后两个成员(Iban和Swift)的CanBeNull属性从false更改为true。 Nothing major, but I need this to be done. 没什么大不了的,但是我需要做到这一点。

Ok, I am assuming you have already set Nullable to True in the Properties window of the Visual Studio when you have the Swift or Iban field selected in the entity designer, and then you have saved to regenerate the .Designer.cs file. 好的,假设您在实体设计器中选择了Swift或Iban字段时,已经在Visual Studio的Properties窗口中将Nullable设置为True ,然后保存以重新生成.Designer.cs文件。 If so (it sounds like you're doing this...), this is what you should be seeing: 如果是这样(听起来您正在执行此操作...),这就是您应该看到的内容:

With Nullable set to True : 将Nullable设置为True

<Column Member="Swift" Storage="_Swift" Type="System.String" CanBeNull="true" UpdateCheck="Always" />

Should generate this: 应该产生这个:

[Column(Storage="_Swift")]
public string Swift
{
...

With Nullable set to False : 将Nullable设置为False

<Column Member="Swift" Storage="_Swift" Type="System.String" CanBeNull="false" UpdateCheck="Always" />

Should generate this: 应该产生这个:

[Column(Storage="_Swift", CanBeNull=false)]
public string Swift
{
...

So as you can see, String is nullable by default, so there is no need for a CanBeNull property in the Column attribute when Nullable is set to True. 如您所见,String默认情况下可为空,因此,当Nullable设置为True时,在Column属性中不需要CanBeNull属性。

Anyway, if the above doesn't provide any more clues, you may need to provide a snippet of your generated code (as I mentioned in a comment on your question). 无论如何,如果上面没有提供任何线索,您可能需要提供所生成代码的摘要(正如我在对问题的评论中提到的那样)。 Hope this helps. 希望这可以帮助。

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

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