Fluent mapping & setting table schemaname

3 posts, 1 answers
  1. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 04 Jul 2012 Link to this post

    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. Answer
    Serge
    Admin
    Serge avatar
    375 posts

    Posted 04 Jul 2012 Link to this post

    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.
  3. DevCraft banner
  4. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 04 Jul 2012 Link to this post

    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
Back to Top