This is a migrated thread and some comments may be shown as answers.

Fluent mapping & setting table schemaname

2 Answers 67 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erik
Top achievements
Rank 2
Erik asked on 04 Jul 2012, 11:13 AM
Hi,

I've been testing OpenAccess Fluent mapping, and must say i've got everything I want (auto inc pk, fk, vertical mapping)
Except I cannot find how to set the Table Schema.

Dim contactConfiguration As New MappingConfiguration(Of Contact)()
contactConfiguration.MapType(Function(p) New With {p}).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("Application.Data.Contacts")
contactConfiguration.HasProperty(Function(f) f.ContactId).IsIdentity(KeyGenerator.Autoinc).HasFieldName("l_ContactId").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("ContactId").IsNotNullable().HasColumnType("bigint").HasPrecision(0).HasScale(0)
contactConfiguration.HasProperty(Function(f) f.Name).HasFieldName("l_Name").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Name").IsNullable().HasColumnType("nvarchar").HasLength(150)
contactConfiguration.HasProperty(Function(f) f.TypeCode).HasFieldName("l_TypeCode").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("TypeCode").IsNullable().HasColumnType("nvarchar").HasLength(50)
contactConfiguration.FieldNamingRules.AddPrefix = "l_"

As you can see I map the table to "Application.Data.Contacts", while the class is called Contact. If I now let OA create the database objects, I'm getting a table "Contacts", but not in the schema "Application.Data". I did create the schema in the db. When I look at what OA creates when making a model via the wizard, it does this. Strangely enough this Contact works fine, and the prefix for the name, the schema, is ignored..

So, how can I set the schema name correct via fluent mapping?

Thanks,

Erik

2 Answers, 1 is accepted

Sort by
0
Accepted
Serge
Telerik team
answered on 04 Jul 2012, 01:30 PM
Hello Erik,

 While the MapTable overload accepts a string as an input it actually is taking in a TableName object (that can be implicitly converted from a string). In order words, you can explicitly specify the schema name by just passing in such an object. Your code should look something like .MapJoinTable(new TableName("table-name", "schema-name")).

I hope this helps. Do let us know should you face further trouble. 

Greetings,
Serge
the Telerik team
OpenAccess ORM Q2'12 Now Available! Get your hands on all the new stuff.
0
Erik
Top achievements
Rank 2
answered on 04 Jul 2012, 04:38 PM
Thanks Serge. Could not find it anywhere and searching on "Schema" will give other results.. so..

this works:
contactConfiguration.MapType(Function(p) New With {p}).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed)
.ToTable(
New TableName("Contacts", "Application.Data"))

Erik
Tags
Getting Started
Asked by
Erik
Top achievements
Rank 2
Answers by
Serge
Telerik team
Erik
Top achievements
Rank 2
Share this question
or