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

The Archive Base Latest Questions

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

I have strange result in database (SQL Server 2008)-. I work on a ASP.NET

  • 0

I have strange result in database (SQL Server 2008)-.

I work on a ASP.NET MVC 3 project with Entity Framework, and I use database migrations.

When I modify the schema of my database, and in configuration file (Configuration.cs) seed method, I have the following code to initialize data after any migration :

protected override void Seed(YAnnonce.Core.Repository.AnnonceDbContext context)
{
   var categorieAnnonces = new List<CategorieAnnonce> 
       {
          new CategorieAnnonce{ CategorieAnnonceID = 1, CategorieName="Emploi"},
          new CategorieAnnonce{ CategorieAnnonceID = 2, CategorieName="Stage"},                        
       };

   categorieAnnonces.ForEach(a => context.CategorieAnnonces.AddOrUpdate(a));
   context.Annonces.AddOrUpdate(new Annonce[10]{
            new Annonce {AnnonceID=250, titre = "Offre d'emploi", CategorieAnnonce = categorieAnnonces[0], description="le cabinet de recrutement le pole offre à toute pe",date=DateTime.Now,etat=1, mode = 0, EndDate = DateTime.Now},
            new Annonce {AnnonceID=490, titre = "Formation", CategorieAnnonce = categorieAnnonces[1], description="Le cabinet de recrutement et de formation maroc ",date=DateTime.Now,etat=0, mode = 1, EndDate = DateTime.Now},
            new Annonce {AnnonceID=380,titre = "Freelance", CategorieAnnonce =categorieAnnonces[1], description="Bonjour, jeune développeur en informatique vous assurant ",date=DateTime.Now, etat=1, mode = 1, EndDate = DateTime.Now});
}

but the problem is that the same data is added to the database after any migration, and I don’t want this scenario.

  • 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-14T23:17:14+00:00Added an answer on June 14, 2026 at 11:17 pm

    You must determine in which state database migration should be used.There are different ways to do this, and i suggest one of them. Write a class like this and put Seed function into it :

    public class DataContextInitializer:DropCreateDatabaseIfModelChanges<YAnnonce.Core.Repository.AnnonceDbContext>
    {
        var categorieAnnonces = new List<CategorieAnnonce> 
           {
              new CategorieAnnonce{ CategorieAnnonceID = 1, CategorieName="Emploi"},
              new CategorieAnnonce{ CategorieAnnonceID = 2, CategorieName="Stage"},                        
           };
    
       categorieAnnonces.ForEach(a => context.CategorieAnnonces.AddOrUpdate(a));
       context.Annonces.AddOrUpdate(new Annonce[10]{
                new Annonce {AnnonceID=250, titre = "Offre d'emploi", CategorieAnnonce = categorieAnnonces[0], description="le cabinet de recrutement le pole offre à toute pe",date=DateTime.Now,etat=1, mode = 0, EndDate = DateTime.Now},
                new Annonce {AnnonceID=490, titre = "Formation", CategorieAnnonce = categorieAnnonces[1], description="Le cabinet de recrutement et de formation maroc ",date=DateTime.Now,etat=0, mode = 1, EndDate = DateTime.Now},
                new Annonce {AnnonceID=380,titre = "Freelance", CategorieAnnonce =categorieAnnonces[1], description="Bonjour, jeune développeur en informatique vous assurant ",date=DateTime.Now, etat=1, mode = 1, EndDate = DateTime.Now});
    }
    

    and then in your main/root web.config file, add below key to run the above class during the application run:

    <appSettings>
        <add key="DatabaseInitializerForType YAnnonce.Core.Repository.AnnonceDbContext, [Project_Name]" value="DataContextInitializer, [Project_Name]" />
    </appSettings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm experiencing something a bit strange. I have a table on SQL Server 2008,
I've faced with a strange problem in ASP.net/SQL Server and really can not find
i'm running into a strange problem in Microsoft SQL Server 2008. I have a
I have a SQL Server 2008 R2 Instance with several databases on it. I'm
I have been using Entity Framework 4.3 on an existing database and I have
I'm using linq to sql for MySql (using DbLinq) in an ASP.NET MVC website.
I have some strange issue with querying SQL Server from django. When I query
We have SQL Server 2000 database with money data type columns and we have
I have a strange issue with a MVC 3 app running as an Azure
I have a LINQ result set I'm trying to filter in a strange and

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.