为什么" LINQ to SQL类"制作类时改变一个表的名字吗? [英] Why does "linq to sql classes" change the name of a table when making a class?

查看:140
本文介绍了为什么" LINQ to SQL类"制作类时改变一个表的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进去,并添加了新的LINQ to SQL类在Visual Studio中,然后再从数据库资源管理器拖放表到新DBML和新类的名称不再是复数。如果我还是希望它是复数?如果我拖到一个表,是不是复数,我得到一个关于已经存在的是如何对所有在我把dbml的布局表中的字段类型定义一堆编译错误。如果我再使类名复数为通过点击姓名和更改它再没有更多的编译错误是不是在dbml的布局复数表。

I go in and add a new "linq to sql classes" in Visual Studio and then go and drag a table from Database Explorer to the new DBML and the name of the new class is no longer plural. What if I still want it to be plural? If I drag a table that isn't plural I get a bunch of compile errors about how there is already a type definition for all of the fields in the table I put on the dbml layout. If I then make the class name plural for the table that wasn't plural in the dbml layout by clicking on the name and changing it then no more compile errors.

推荐答案

您可以一次点击在dbml的表中的表名并重新命名。或者你可以在DBML选择表,然后转到属性窗口。在那里,您可以更改名称,以及表它挂钩到。

You can single click on the tablename in the dbml table and rename it. Or you can select the table in the DBML and go to the properties window. There you can change the name, and the table it hooks up to.

,以避免名称冲突的一种方法是相应指定名称空间。例如,您可以将您的DBML文件在项目中的子文件夹,并为其分配类似数据访问。因此,当您映射到Ling2Sql类,你会做DataAccess.Customer,您可以避免与客户发生冲突,因为它生活在别处。

One way to avoid the name conflict is to designate namespaces accordingly. For example, you can place your DBML file in a subfolder in your project and assign it something like DataAccess. Therefore, when you map to the Ling2Sql class, you'd do DataAccess.Customer and you can avoid the conflict with Customer, since it lives somewhere else.

作为珍闻,LINQ2SQL在默认情况下,使表的非复数。它是基于掀起了公约。例如,Customers表拥有众多的客户。当你实例化一个对象,你在看一个客户,不表。对象基本上被映射到客户表中的一行,因此,它会变成奇异。

As a tidbit, Linq2Sql by default makes tables non-plural. It's based off of a convention. For example, a table Customers has many customers. When you instantiate an object, you're looking at a single Customer, not the table. The object is essentially being mapped to a row in the Customers table, thus it becomes singular.

这篇关于为什么" LINQ to SQL类"制作类时改变一个表的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆