SqlMetal 生成垃圾关联名称
为什么 SqlMetal 会搞乱协会名称。 例如,在我的“TextMessage”表中,我有两列引用“ApplicationUser”表。 'SenderUserId' 和 'RecipientUserId'
当我运行 SqlMetal 并查看我的 'ApplicationUser' 类
对于 'RecipientUserId' 它生成:
[Association(Name="FK__TextMessa__Recip__72910220", Storage="_TextMessages", ThisKey="Id", OtherKey="RecipientUserId", DeleteRule="NO ACTION")]
public EntitySet<TextMessage> TextMessages
{
get
{
return this._TextMessages;
}
set
{
this._TextMessages.Assign(value);
}
}
对于 'SenderUserId' 它生成这个名为属性的垃圾:
[Association(Name="FK__TextMessa__Sende__73852659", Storage="__TextMessa__Sende__73852659s", ThisKey="Id", OtherKey="SenderUserId", DeleteRule="NO ACTION")]
public EntitySet<TextMessage> _TextMessa__Sende__73852659s
{
get
{
return this.@__TextMessa__Sende__73852659s;
}
set
{
this.@__TextMessa__Sende__73852659s.Assign(value);
}
}
我该如何补救? 这是无法使用的。 有没有更好的方法来生成 Linq To Sql 代码???
Why is SqlMetal messing up the Association names. For e.g. in my 'TextMessage' table i have two columns referencing the 'ApplicationUser' table. 'SenderUserId' and 'RecipientUserId'
When I run SqlMetal and look at my 'ApplicationUser' class
For 'RecipientUserId' it generates:
[Association(Name="FK__TextMessa__Recip__72910220", Storage="_TextMessages", ThisKey="Id", OtherKey="RecipientUserId", DeleteRule="NO ACTION")]
public EntitySet<TextMessage> TextMessages
{
get
{
return this._TextMessages;
}
set
{
this._TextMessages.Assign(value);
}
}
and for 'SenderUserId' it generates this garbage named property:
[Association(Name="FK__TextMessa__Sende__73852659", Storage="__TextMessa__Sende__73852659s", ThisKey="Id", OtherKey="SenderUserId", DeleteRule="NO ACTION")]
public EntitySet<TextMessage> _TextMessa__Sende__73852659s
{
get
{
return this.@__TextMessa__Sende__73852659s;
}
set
{
this.@__TextMessa__Sende__73852659s.Assign(value);
}
}
How can I remedy this? This is unusable. Is there a better way to generate Linq To Sql Code???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它根据外键生成名称。 将外键命名为比自动生成的名称更易读的名称。 例如:
约束 RecipientMessages FOREIGN KEY(RecipientUserId) 引用 ApplicationUser(UserId)
It's generating the name based on the foreign key. Name your foreign key something more readable than the auto generated name. for example:
constraint RecipientMessages FOREIGN KEY(RecipientUserId) references ApplicationUser(UserId)
您可以指示 SqlMetal 生成 DBML 文件:
然后更正 DBML 文件中的关联名称,然后从 DBML 生成:
这样做的唯一问题是,如果在更新数据库后重新生成 DBML,则对你的 DBML 将被洗掉。
其他选项:
更进一步的一点:我很少看到 SqlMetal 发出如此糟糕的关联名称。 你的专栏是如何命名的? 是否与其他关系名称冲突?
You can instruct SqlMetal to generate a DBML file:
and then correct the association names in the DBML file and then generate from the DBML:
The only problem with doing this is that if you re-generate the DBML after updating your database, any changes to your DBML will wash out.
Other options:
One further point: I've rarely seen SqlMetal emit an association name that bad. How are your columns named? Is there a conflict with another relationship name?