I am testing EF6 code first against a simple table in an existing SQL Anywhere 12.0.1 database. I tested DB first and had no problems querying with that method. But my attempts with code first won't work.

Here's the table:

CREATE TABLE "DBA"."COUNTRY" (
    "country_id"                     char(2) NOT NULL
   ,"name"                           char(30) NOT NULL
   ,"country_code"                   varchar(3) NULL
   ,PRIMARY KEY ("country_id") 
)
go

Imagine the data in the table as 'CA','Canada','CAN' 'US','United States','USA' 'FR','France','FR' etc...

The model class:

<Table("COUNTRY")>
Partial Public Class COUNTRY
    <Key>
    Public Property country_id As String
    Public Property name As String
    Public Property country_code As String
End Class

And the DbContext class:

Partial Public Class MyEntities
    Inherits DbContext
Public Sub New() MyBase.New("name=MyConnStr") End Sub
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder) Data.Entity.Database.SetInitializer(Of MyEntities)(Nothing) MyBase.OnModelCreating(modelBuilder) End Sub
Public Overridable Property Country() As DbSet(Of COUNTRY)

End Class

When I attempt to do code like the following: Dim db As New MyEntities Dim lstCountry = db.Country.ToList()

lstCountry.Count returns zero... What am I doing wrong?

asked 04 Jun '15, 13:53

voonliew's gravatar image

voonliew
106333
accept rate: 25%

edited 04 Jun '15, 14:01


Oh man... I'm so stupid. :)

I just needed to add the schema to table attribute. <Table("COUNTRY", Schema:="dba")>

So... anyway to assign a default schema to EF mappings?

permanent link

answered 04 Jun '15, 16:18

voonliew's gravatar image

voonliew
106333
accept rate: 25%

1

See: http://stackoverflow.com/questions/9562883/can-i-change-the-default-schema-name-in-entity-framework-4-3-code-first

This method exists in EF6:

public class Context : DbContext
{
    public DbSet<User> Users { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.HasDefaultSchema("dba");
    }
}
(05 Jun '15, 18:24) Jeff Albion
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×65
×61

question asked: 04 Jun '15, 13:53

question was seen: 820 times

last updated: 05 Jun '15, 18:24