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 9132851
In Process

The Archive Base Latest Questions

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

TranslationItem Model: [DataContract] public class TranslationItem : CloneableBaseEntity<TranslationItem>, IValidatableObject { public int TranslationId {

  • 0

TranslationItem Model:

[DataContract]
public class TranslationItem : CloneableBaseEntity<TranslationItem>, IValidatableObject
{

    public int TranslationId { get; set; }
    public Translation Translation { get; set; }

    public int Lcid { get; set; }        

    private string _text;
    public string Text
    {
        get { return _text; }
        set
        {
            _text = value;
            RaisePropertyChanged("Text");
        }
    }

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        var t = validationContext.ObjectInstance as TranslationItem;   
        return t.Translation.Validate(validationContext);               
    }
}

Translation Model:

[DataContract]
public class Translation : CloneableBaseEntity<Translation>, IValidatableObject
{
    private static int _englishLcid = 9;

    private  ObservableCollection<TranslationItem> _translations;
    [DataMember]
    public virtual ObservableCollection<TranslationItem> Translations
    { 
        get{
            return _translations;
        }
        set
        {
            _translations = value;
            foreach (TranslationItem ti in _translations)
            {
                ti.PropertyChanged += ti_PropertyChanged;
            }
        }
    }

    ...
    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext){ 

        Translation t;
        if(validationContext.ObjectInstance.GetType()== typeof(Translation))
            t = validationContext.ObjectInstance as Translation;
        else
            t =( validationContext.ObjectInstance as TranslationItem).Translation;

        if (!t.EnglishNotRequried)
        {
            if (!t.TranslationDict.ContainsKey(_englishLcid) || String.IsNullOrEmpty(t.TranslationDict[_englishLcid].Text))
            {
                yield return new ValidationResult("EnglishTranslationMissing");
            }
        }
    }
} 

my Seed method in my migration Configuration class

protected override void Seed(DbContext context)
{
    int deLcid = new CultureInfo("en").LCID;
    int enLcid = new CultureInfo("en").LCID;


    TranslationItem enStd = context.TranslationItems.FirstOrDefault(ti => ti.Text == "Standard" && ti.Lcid == enLcid)
                            ?? new TranslationItem { Text = "Standard", Lcid = enLcid };

    TranslationItem deStd = context.TranslationItems.FirstOrDefault(ti => ti.Text == "Standard" && ti.Lcid == deLcid)
                            ?? new TranslationItem { Text = "Standard", Lcid = deLcid };

    context.Translations.AddOrUpdate(
        t => t.Translations,
        new Translation
            {
                Translations = new ObservableCollection<TranslationItem>
                    {
                        enStd,
                        deStd
                    }
            });

    context.SaveChanges();

    context.EventTypes.AddOrUpdate(
        et => et.Name,
        new EventType
        {
            Name = context.Translations.FirstOrDefault(t => t.Translations.Any(x => x.Lcid == enLcid && x.Text == "Standard") &&
                                                            t.Translations.Any(x => x.Lcid == deLcid && x.Text == "Standard") )
        });             
}

i get the following error when i want to update-database

Unable to create a constant value of type 'PQS.Model.TranslationItem'. Only primitive types or enumeration types are supported in this context.

im not quite sure how i can fix this problem.
i already tried to insert my TranslationItems first, but when i do this the validation fails because there is a FK to Translations required i guess.

PLEASE HELP!!

  • 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:23:05+00:00Added an answer on June 17, 2026 at 8:23 am

    fixed it by my own with a little hack (not exactly my prefered solution but it works for now)

    my problem: it seems that with a AddOrUpdate(...) i can only compare primitive types or enum types.

    so i added an additional id called SeedId to identify my entities.

    so my code in the seed method is very simple now :

    foreach (EventType eventtype in PqsDbContext.getStdEventTypes())
    {
        context.EventTypes.AddOrUpdate(et => et.SeedId, eventtype);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following database tables/EF objects public class Transaction { //some other properties
I defined two classes. First one... [Serializable] public class LocalizationEntry { public LocalizationEntry() {
I have been trying the model-first method when designing my application. We usually like
class TransactionItem < ActiveRecord::Base belongs_to :transaction end class Transaction < ActiveRecord::Base has_many :transaction_items def
Invoking the following query when there is no Entity record in the database throws
I currently need to execute a database query that involves data from three separate
I use EF 5 and Code First. Ive got a main ViewModel that exposes
I'm trying to remove doublettes (sometimes triplettes, unfortunately!) from a MySQL table. My issue
Not sure if I worded this correctly ... but I have the following code:

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.