on 2015 Jun 04 2:53 PM
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?
Request clarification before answering.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This method exists in EF6:
public class Context : DbContext
{
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("dba");
}
}
User | Count |
---|---|
75 | |
30 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.