Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:14:54+00:00 2026-06-17T08:14:54+00:00

Edit: full source code now available at https://bitbucket.org/moerie/multilanguagestring I’ve implemented a class called MultilingualString

  • 0

Edit: full source code now available at https://bitbucket.org/moerie/multilanguagestring

I’ve implemented a class called MultilingualString which can serialize a dictionary to XML and be saved to the database.

(See source here: https://gist.github.com/4491990 )

This is actually an implementation of IDictionary but I don’t actually add that to my class as it seems to cause hiccups for the Entity Framework.

usage of this class is like follows:

Suppose a class Product is defined like this:

public class Product
{
    public int Id { get; set; }

    public virtual MultilingualString Description { get; set; }

    public virtual MultilingualString Name { get; set; }
}

Then you can do the following:

        // make some products
        var product1 = new Product
        {
            Id = 1,
            Name = new MultilingualString(),
            Description = new MultilingualString()
        };
        product1.Name["fr"] = "Produit 1";
        product1.Description["fr"] = "Déscription 1";
        product1.Name["nl"] = "Produkt 1";
        product1.Description["nl"] = "Omschrijving 1";

Anyway, since I only want the Id and the Xml value I made an EntityTypeConfiguration:

public class MultilingualStringConfiguration: EntityTypeConfiguration<MultilingualString>
{
    public MultilingualStringConfiguration()
    {
        Ignore(m => m.Count);
        Ignore(m => m.Keys);
        Ignore(m => m.Values);
        Ignore(m => m.IsReadOnly);
    }
}

When I run this code, the MultilingualStrings table is created as followed:

CREATE TABLE [dbo].[MultilingualStrings](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Value] [nvarchar](max) NULL,
    [Item] [nvarchar](max) NULL,
 CONSTRAINT [PK_dbo.MultilingualStrings] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

As you can see, the Entity Framework adds a property called ‘Item’, and I suspect this is because of the following property in MultilingualString:

    /// <summary>
    /// Gets or sets the element with the specified key. 
    /// </summary>
    /// <returns>
    /// The element with the specified key.
    /// </returns>
    /// <param name="key">The key of the element to get or set.</param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception><exception cref="T:System.Collections.Generic.KeyNotFoundException">The property is retrieved and <paramref name="key"/> is not found.</exception><exception cref="T:System.NotSupportedException">The property is set and the <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.</exception>
    public string this[string key]
    {
        get
        {
            if (ContainsKey(key))
                return Translations[key];
            return string.Empty;
        }
        set
        {
            Translations[key] = value;
            UpdateValue();
        }
    }

This is the property that allows my MultilingualString property to be used as a Dictionary, but sadly I can’t seem to reach this property from the EntityTypeConfiguration.

How can I ignore this property? Thanks in advance.

P.S. For those of you interested in the MultilingualString class, note that you will need the LinqKit library (and specifically the AsExpandable() and Compile() functions to perform Linq queries with this class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:14:55+00:00Added an answer on June 17, 2026 at 8:14 am

    Full source code:

    https://bitbucket.org/moerie/multilanguagestring

    Since this MultilingualString is in fact a property, I tried to resolve my problem by just mapping my MultilingualString to a String property. Then I could just tell the Entity Framework to not map my MultilingualString property entirely.

    This is my product class now:

    public class Product
    {
        private MultilingualString _description;
        private MultilingualString _name;
    
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id { get; set; }
    
        public virtual string DescriptionXml
        {
            get { return Description.Value; }
            set { Description.Value = value; }
        }
    
        public virtual string NameXml
        {
            get { return Name.Value; }
            set { Name.Value = value; }
        }
    
        [NotMapped]
        public virtual MultilingualString Description
        {
            get { return _description ?? (_description = new MultilingualString()); }
            set { _description = value; }
        }
    
        [NotMapped]
        public virtual MultilingualString Name
        {
            get { return _name ?? (_name = new MultilingualString()); }
            set { _name = value; }
        }
    }
    

    This also seriously simplifies my database.

    Yes, I couldn’t find a fluent API solution for my original problem, but this workaround turned out to be excellent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
Initially i added full source code for viewer. but it has some format problem
I have an in-house HTTP server written in Java; full source code at my
I have a grok'ed plone.directives.form code below: class EditForm(TreeFormMixin, form.SchemaForm): Edit form for our
When reading source code, I always want to know the full path of the
FULL EDIT: I urgently need to access a Microsoft SQL Server and read compressed
I have some PHP source code that I'm hosting with hosting company XYZ. I'm
I got an .ipa file from a customer (without source code access). This app
EDIT Updated code with solution I need to transcode amr to mp3, so i
I am trying to produce multiple InfoWindows with the following code: EDIT: To clarify,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.