如何自动创建与访问表兼容的类?

发布于 2024-11-08 23:21:50 字数 658 浏览 0 评论 0原文

我想使用 Linq 连接到 access2007 数据库(我不想使用 ado.net)。

我看到了一些例子,但它们都创建了一个我想从数据库导入的对象的类,例如,

 public class Company
 {
     public string Name
     { get; set; }

     public List ListEmp
     { get; set; }
 }

var EmpDetails = from comp in ListCompany
                          select new
                          {
                              Emp = (from emp in comp.ListEmp
                                     select new { Company = comp.Name, emp })
                          };

当你有一个小数据库时,这很容易,但我有一个表中有 30 个属性的数据库,所以很难专门为表中的对象创建一个类,

所以有没有一种更简单的方法,例如自动创建与表中的对象兼容的对象,

如果我不清楚,请告诉我,以便我可以澄清,

谢谢

i want to use Linq to connect to a access2007 database (i don't want to use ado.net).

i saw some examples but all of them make a class of the object i want to import from the database for example

 public class Company
 {
     public string Name
     { get; set; }

     public List ListEmp
     { get; set; }
 }

var EmpDetails = from comp in ListCompany
                          select new
                          {
                              Emp = (from emp in comp.ListEmp
                                     select new { Company = comp.Name, emp })
                          };

thats is easy when u have a small database , but i have a database with 30 attribute in a table so it will be hard to make a class specifically for the object from the table

so is there a way easier like automatically create an object compatible with the objects from the table

if i wasn't clear please tell me so i could clarify it

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲凉≈ 2024-11-15 23:21:50

首先,请注意 LINQ-to-SQL 尚未(据我所知)验证可在 Access 上使用。它通常有效,但是MMMV。

就我个人而言,我会通过将表从 Access 数据库导入(迁移)到 SQL Server Express 实例中来解决此问题,并使用它来生成模型(当然,该工具甚至可能适用于 Access,但我认为他们没有 - 因此就是这个问题)。生成模型后,您应该能够将其(在运行时 - 通过连接字符串或连接)指向您的访问数据库。

您可能还会考虑:为什么不将其保留为 SQL Server Express 节点 - 它运行良好,并且在 LINQ-to SQL 方面得到更好的支持。

另请注意,还有其他类似 LINQ-to-SQL 的工具可能适合您的目的; DbLinq、dapper-dot-net 等 - 以及一些重量级工具(EF、NHibernate、LLBLGen Pro 等)

First, note that LINQ-to-SQL is not (AFAIK) validated for use on Access. It generally works, but MMMV.

Personally, I would approach this by importing (migrating) the tables from the Access database into a SQL Server Express instance, and using that to generate the model (of course, the tooling might even work against Access, but I assume they don't - hence the question). With the model generated, you should be able to point it (at runtime - via connection-string or connection) at your access database instead.

You might also consider: why not leave it as a SQL Server Express node - it works well, and is better supported in terms of LINQ-to-SQL.

Note also that there are other LINQ-to-SQL-like tools that may work for your purposes; DbLinq, dapper-dot-net, etc - and a few more heavy-weight tools (EF, NHibernate, LLBLGen Pro, etc)

故人的歌 2024-11-15 23:21:50

XPO,来自 Developer Express,将允许您直接从 Access 2007/2010 数据库创建 .Net 类并使用 Linq 创建查询。

好处是,如果您希望更改数据库后端,例如您将数据从 Access 传输到 SQL Server 或 MySQL 或 PostgreSQL 等 您只需要更改数据库连接字符串,而不是您的代码。

文档可在线获取

XPO, an ORM tool from Developer Express, would allow you to create .Net classes directly from your Access 2007/2010 database and use Linq to create queries.

The good thing is that if you wish to change database backend, say for instance that you transferred your data from Access to SQL Server or MySQL or PostgreSQL, etc you just need to change the database connection string, not your code.

Documentation is available online.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文