EF4 CTP5代码第一种方法忽略表属性 [英] EF4 CTP5 Code First approach ignores Table attributes

查看:333
本文介绍了EF4 CTP5代码第一种方法忽略表属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是EF4 CTP5代码的第一种方法,但是无法使其工作。我有一个名为公司的类和一个名为CompanyTable的数据库表。我想将公司类映射到CompanyTable表,所以有这样的代码:

  [Table(Name =CompanyTable )] 
public class Company
{
[Key]
[Column(Name =CompanyIdNumber,DbType =int)]
public int CompanyNumber {get ;组; }

[Column(Name =CompanyName,DbType =varchar)]
public string CompanyName {get;组;
}

然后我打电话给它:

  var db = new Users(); 
var companies =(from c in db.Companies
select c).ToList();

但是它出错:



无效的对象名称'dbo.Companies'。



显然不尊重类中的Table属性,即使它表示这里表属性被支持。另外它是多元化它搜索的名称(公司而不是公司)。如何将类映射到表名?

解决方案

忘记添加对我的schemas项目的ctp5 dll的引用,它正在使用System.Data.Linq.Mapping。


I'm using EF4 CTP5 code first approach but am having trouble getting it to work. I have a class called "Company" and a database table called "CompanyTable". I want to map the Company class to the CompanyTable table, so have code like this:

[Table(Name = "CompanyTable")]
    public class Company
    {
        [Key]
        [Column(Name = "CompanyIdNumber", DbType = "int")]
        public int CompanyNumber { get; set; }

        [Column(Name = "CompanyName", DbType = "varchar")]
        public string CompanyName { get; set; }
    }

I then call it like so:

var db = new Users();
            var companies = (from c in db.Companies
                            select c).ToList();

However it errors out:

Invalid object name 'dbo.Companies'.

It's obviously not respecting the Table attribute on the class, even though it says here that Table attribute is supported. Also it's pluralizing the name it's searching for (Companies instead of Company.) How do I map the class to the table name?

解决方案

Forgot to add a reference to the ctp5 dll to my schemas project, it was using System.Data.Linq.Mapping instead.

这篇关于EF4 CTP5代码第一种方法忽略表属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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