EF4 CTP5 Code First approach ignores Table attributes

Posted by Justin on Stack Overflow See other posts from Stack Overflow or by Justin
Published on 2010-12-20T20:49:37Z Indexed on 2010/12/27 3:54 UTC
Read the original article Hit count: 318

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?

© Stack Overflow or respective owner

Related posts about entity-framework-4

Related posts about code