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

  • Home
  • SEARCH
  • 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 6535765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:24:41+00:00 2026-05-25T10:24:41+00:00

I’m fetching information from a webpage in two pages: First page: – Content c1

  • 0

I’m fetching information from a webpage in two pages:

First page:
– Content c1 is created and a Translation c1.t1 is created;
– Content c2 is created and Translation c2.t1 is created;

Second page:
– The system detects that c1 already exists and just adds c1.t2 to the proper table;
– The system detects that c2 already exists and just adds c2.t2 to the proper table;

Somehow, on the second page, the system is overritting c1.t1 with c1.t2 and only the second translation is available on the database. When debbugging, found that it is deletting c1.t1 at some point but I couldn’t figure out why.

This is my actual stuff:

  • EF 4.1
  • Code-First Aproach
  • DbContext

I have this POCO Entities (minimized):

RegionalContent: – It’s like a tranlation and regional info about a content:

public class XBLRegionalContent
{
    [Key, Column(Order = 0)]
    public string ContentId { get; set; }

    [ForeignKey("ContentId")]
    public virtual XBLContent Content { get; set; }


    [Key, Column(Order = 1)]
    public string RegionId { get; set; }

    [ForeignKey("RegionId")]
    public virtual XBLRegion Region { get; set; }

    public string Name { get; set; }
}

Content: – Unique content per GUID:

public class XBLContent
{
    #region [ Properties ]
    /// <summary>
    /// The GUID
    /// </summary>
    [Key]
    [StringLength(36, ErrorMessage="Must have 36 characters")]
    [Required(ErrorMessage="Must have a unique GUID")]
    public string GUID { get; set; }

    public string Type { get; set; }

    public virtual ICollection<XBLRegionalContent> RegionalInfo { get; set; }
}

Region – Pretty straight forward:

public class XBLRegion
{
    [Key]
    [StringLength(5, ErrorMessage="ID must have 5 characters")]
    [Required]
    [RegularExpression(@"[a-z]{2}-[A-Z]{2}", ErrorMessage = "ID must be in ISO 639 standard")] 
    public string ID { get; set; }

    public string Country { get; set; }

    public string Language { get; set; }
}

DbContext class has nothing different, just DbSets.

One content has many translations. One translation has one content related. The translation primary key is compound of content guid and region id.

I have a class in Model that populates the database and creates a local list that the View uses to display information. That way, I only access the Database one time to save, and don’t need to retrieve information when it is saved.

Here is only the important information about this class:

public class XBLChart : IDisposable
{
    XBLContentContext db = new XBLContentContext();
    private string baseurl = "http://foo.bar/";

    public string Locale { get; private set; }
    public string HTML { get; private set; }
    public string URL { get; set; }
    public ContentType Type { get; private set; }

    public List<XBLContent> Contents { get; set; }

    public XBLChart(ContentType type, string sort, string locale)
    {
        Type = type;

        if (sort == null)
            sort = Enum.GetName(typeof(SortBy), SortBy.OfferStartDate);

        if (locale != null && locale.Length == 5)
            Locale = locale;
        else
            Locale = "en-US";

        URL = baseurl + Locale + "/" + sort;
        HTML = FeedUtils.RequestHTML(URL);

        Contents = new List<XBLContent>();

        PopulateList();
    }

    private void PopulateList()
    {
        MatchCollection itens = Regexes.ChartItems().Matches(HTML);
        MatchCollection titulos = Regexes.ChartTitles().Matches(HTML);

        int type = (int)Type;
        int start = type * 12;

        this.Title = HttpUtility.HtmlDecode(titulos[type].Groups["title"].Value);

        if (titulos.Count < 8 && start > 1)
        {
            start = (type - 1) * 12;
            type--;
        }

        XBLRegion region;
        if (!db.XBLRegions.Any(x => x.ID == Locale))
        {
            region = new XBLRegion { ID = Locale };
            db.XBLRegions.Add(region);
            db.SaveChanges();
        }
        else
            region = db.XBLRegions.SingleOrDefault(x => x.ID == Locale);


        for (int i = start; i < (start + 2); i++)
        {
            string guid = itens[i].Groups["guid"].Value;

            XBLContent c = new XBLContent(guid);
            if (!db.XBLContents.Any(x => x.GUID == guid))
            {
                c.Type = Type.ToString();
                c.PopularInfo(Locale);

                db.XBLContents.Add(c);
            }
            else
                c = db.XBLContents.Single(x => x.GUID == c.GUID);

            XBLRegionalContent regionalcontent = new XBLRegionalContent(guid, Locale);                
            if (!db.XBLRegionalInfos.Any(x => x.ContentId == guid && x.RegionId == Locale))
            {
                if (c.HTML == null)
                    c.PopularInfo(Locale);

                regionalcontent.Populate(c.HTML);
                regionalcontent.Name = HttpUtility.HtmlDecode(itens[i].Groups["name"].Value);

                db.XBLRegionalInfos.Add(regionalcontent);                    
            }
            else
                regionalcontent = db.XBLRegionalInfos.Single(x => x.ContentId == guid && x.RegionId == Locale);

            db.SaveChanges();

            c.RegionalInfo.Clear();
            regionalcontent.Region = region;
            c.RegionalInfo.Add(regionalcontent);

            Contents.Add(c);
        }
    }
}
  • 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-05-25T10:24:42+00:00Added an answer on May 25, 2026 at 10:24 am

    you are missing a db.SaveChanges() after

    db.SaveChanges();
    
    c.RegionalInfo.Clear();
    regionalcontent.Region = region;
    c.RegionalInfo.Add(regionalcontent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.