NVarchar Mapping

4 posts, 0 answers
  1. Herbert
    Herbert avatar
    4 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    Hi,

    I have a mapped class with some string properties. Fluent mapping always results in a schema with "varchar" columns for SQL server.
    The documentation states that it is possible to specify "nvarchar" columns as default using the app.config/web.config.

    However for my current project I won't be able to use an app.config file.
    I've tried to create a default mapping to "nvarchar" in code, but this failed:

    protected override MetadataContainer CreateModel()
    {
        MetadataContainer container = base.CreateModel();
        container.DefaultMapping.NullForeignKey = true;
        container.NameGenerator.UseModelNames = true;
        container.DefaultMapping.ClrMap.Add(new DefaultTypeMapping()
        {
            ClrType = typeof(String).Name,
            SqlType = "nvarchar",
            AdoType = OpenAccessType.Varchar
        });
        return container;
    }

    So what I'm asking for: how can I create such a default type mapping in code ?

    Thank you

    Herbert
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 15 Aug 2012 Link to this post

    Hi Herbert,

     The approach you are trying to apply is an internal representation of the type mapping which is not recommended to be explicitly changed by the user at this stage. We will improve that API and provide capabilities for better manipulation of the default type mapping.

    We have however, provided a way to map your string fields via Fluent API to nvarchar instead of varchar (and the respective types according to the type of backend used). You should apply the approach described in this help article, or more precisely, you need to use the IsUnicode() method described there.

    All the best,
    Zoran
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
  4. Herbert
    Herbert avatar
    4 posts
    Member since:
    Aug 2012

    Posted 15 Aug 2012 Link to this post

    Hi Zoran,

    I've seen that this feature is on the roadmap but not yet in the actual assembly (at least not in the free version).
    When can we expect the new release ?

    Thank you for your great support.

    Herbert
  5. Ivailo
    Admin
    Ivailo avatar
    318 posts

    Posted 20 Aug 2012 Link to this post

    Hi Herbert,

    While the Visual Designer part of this functionality is not yet released, in our latest official build (Service pack 2) you can find the Fluent API enhancements that would allow you to define your mapping in a backend-independent way. 

    You can give it a try and we are looking forward to any feedback you can share with us, so that we can consider any possible improvements for the Q3 release.


    All the best,
    Ivailo
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top