当前上下文中不存在名称“数据库"? [英] The name 'Database' does not exist in the current context?

查看:86
本文介绍了当前上下文中不存在名称“数据库"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 WebMatrix 启动我的网站时出现此错误.我有一个 .cs 文件,它调用 var db = Database.Open("dbase");.

I am getting this error when I try to launch my website using WebMatrix. I have a .cs file which makes a call var db = Database.Open("dbase");.

我的项目中有一个名为dbase"的数据库.我没有 web.config 文件,也没有使用 WebMatrix 包的导入,因为我使用 WebMatrix 启动站点,所以我认为我不需要它们.我是否需要将代码包装在 Razor 标签中,例如 @{var db = Database.Open("dbase");} ?这也给我带来了错误.

I have a database in my project called "dbase". I have no web.config file and no imports for using WebMatrix packages since I am launching the site using WebMatrix, so I don't believe I should need them. Do I need to wrap the code in Razor tags, like @{var db = Database.Open("dbase"); } ? This causes an error for me too.

可能是什么原因造成的?有没有人对此有任何解决方案?

What could be causing this? Does anyone have any solutions for this?

推荐答案

您需要对 WebMatrix.Data.dll 程序集(您可能拥有)的引用,并且您还em> 需要一个用于 WebMatrix.Data 命名空间的 using 指令:

You need a reference to the WebMatrix.Data.dll assembly (which you probably have) and you also need a using directive for the WebMatrix.Data namespace:

using WebMatrix.Data;

这将导入数据库 类,因此您无需完全限定名称即可使用它.

That will import the Database class so you can use it without fully-qualifying the name.

不清楚为什么你认为你不需要任何导入"(我假设你的意思是使用上面的指令)但是如果这是在一个普通的 C# 文件中,那么你当然 do 需要它们(或者您需要完全限定类型名称,这很丑陋).

It's not clear why you think you wouldn't need any "imports" (by which I assume you mean using directives like the one above) but if this is in a plain C# file, then you certainly do need them (or you need to fully-qualify type names, which is ugly).

这篇关于当前上下文中不存在名称“数据库"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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