反对的MS Access LINQ asp.net页面。 [英] LINQ asp.net page against MS Access .

查看:97
本文介绍了反对的MS Access LINQ asp.net页面。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ADO查询MS Access数据库作为一个学习锻炼我想结合LINQ有一个ASP.Net网页。我有一个简单的表名为行情。

I have a ASP.Net page using ADO to query MS access database and as a learning exercise i would like to incorporate LINQ. I have one simple table called Quotes.

字段有:QuoteID,QuoteDescription,QuoteAuthor,QuoteDate。我想运行简单的查询,如给我所有的报价在1995年以后。

The fields are: QuoteID, QuoteDescription, QuoteAuthor, QuoteDate. I would like to run simple queries like, "Give me all quotes after 1995".

我怎么会合并LINQ到这个ASP.Net网站(C#)

How would i incorporate LINQ into this ASP.Net site (C#)

基本上,我的问题是确实的MS Access LINQ工作??

Basically, my question is does LINQ work for MS Access ??

推荐答案

LINQ to SQL的不支持访问(即,有对LINQ没有访问/ Jet提供),但你可以查询与LINQ数据集。这意味着你填写你的DataSet从数据库中,您可能需要在搜索结果中可能出现的数据,然后在客户端进行过滤。之后,你有类型化的DataSet,和你填写()将其与一个TableAdapter,你做这样的事情:

LINQ to SQL doesn't support Access (that is, there's no Access/Jet provider for LINQ), but you can query a DataSet with LINQ. This means that you fill your DataSet with any possible data from your database that you might need in your results, and then you filter on the client side. After you have a typed DataSet, and you Fill() it with a TableAdapter, you do something like this:

var year = 1995;  // you can pass the year into a method so you can filter on any year
var results = from row in dsQuotes
              where row.QuoteDate > year
              select row;

您必须决定这是否是值得的。你有来填补你的数据集的所有的引号,然后使用LINQ要过滤的只是那些1995年后的数据,当然,为什么不少量的报价?但是对于数据量非常大的,你需要确保它不会太慢。

You'll have to decide whether this is worth it. You'd have to fill your DataSet with all the quotes, then use LINQ to filter on just those quotes that are after 1995. For a small amount of data, sure, why not? But for a very large amount of data, you'll need to make sure it won't be too slow.

如果您使用的是数据集,不过,你可以写成为新的TableAdapter方法​​的自定义查询。所以,你可以把正确的SQL为在你的TableAdapter一个FillByYear()方法查询和使用,来填补你的类型的DataTable。这样,你只找回需要的数据。

If you're using a DataSet, though, you can write custom queries that become new TableAdapter methods. So you can put the correct SQL for your query in a FillByYear() method in your TableAdapter and use that to fill your typed DataTable. That way you're only getting back the data you need.

如果你走这条路,记得访问/喷气机使用位置参数,而不是命名参数。因此,而不是

If you go this route, remember that Access/Jet uses positional parameters, not named parameters. So instead of

SELECT * FROM Quotes WHERE Year(QuoteDate) > @Year

您会使用这样的:

SELECT * FROM Quotes WHERE Year(QuoteDate) > ?

这篇关于反对的MS Access LINQ asp.net页面。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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