linq和localhost,实体名称空间不同于程序名称空间,但仍然得到错误

ibps3vxo  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(399)

我试着搜索这个,但是我发现的每个例子都有一个问题,比如它们实际上和它们的类或其他东西有相同的名称空间。
我只是想开始使用linq。添加新项目时,主机是localhost。我的数据库在visualstudio中,我的项目名称与datacontext名称不同,但无法将其初始化。我得到错误:
'linkedcontext'是命名空间,但用作类型'
这是密码。。。

  1. namespace TryAgain
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. LinkedContext db = new LinkedContext();
  8. }
  9. }
  10. }

linkedcontext不工作?在数据库关系图的设置中,它说实体名称空间是'linkedcontext',所以我遗漏了什么。我想我看到你可以运行一行代码来连接你的数据库,因为它已经在visualstudio中添加了一个新的项目,然后开始玩它?我只想练习一下数据库!像这样做:

  1. var example = from x in example.Table
  2. orderby x.field
  3. select x;
c9qzyr3d

c9qzyr3d1#

你需要 using LinkedContext 在你文件的顶端。你得到的错误告诉你 LinkedContext 是一个名称空间,但您将其视为一个类型(即类)。在顶部定义之后,就可以在名称空间中使用所需的类型。

4sup72z8

4sup72z82#

在代码顶部添加了“using linkedcontext”,然后还必须使用linkeddatacontext,而不仅仅是linkedcontext:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using LinkedContext;
  7. namespace TryAgain
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. LinkedDataContext db = new LinkedDataContext();
  14. var example = from x in db.employees
  15. orderby x.employee_id
  16. select x;
  17. foreach (var whatever in example)
  18. {
  19. Console.WriteLine(whatever.name);
  20. }
展开查看全部

相关问题