Please be aware that the SAP SQL Anywhere Forum will be shut down on August 29th, 2024 when all it's content will be migrated to the SAP Community.

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:

    "country_id"                     char(2) NOT NULL
   ,"name"                           char(30) NOT NULL
   ,"country_code"                   varchar(3) NULL
   ,PRIMARY KEY ("country_id") 

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

The model class:

Partial Public Class COUNTRY
    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

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

accept rate: 25%



This method exists in EF6:

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

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
(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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 04 Jun '15, 13:53

question was seen: 3,740 times

last updated: 05 Jun '15, 18:24