Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Storing deserialized data into SQL Server Ce using Entity Framework code first

Storing deserialized data into SQL Server Ce using Entity Framework code first

Scheduled Pinned Locked Moved C#
databasehelpsql-serversysadminxml
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sifi mohamed amine
    wrote on last edited by
    #1

    I need to add deserialized data from xml file to the model in Entity Framework cod efirst in order to generate my database in SQL Server CE. The problem was that I have two tables , the first was done without problems but when I added the second model I got an exception : {"Exception has been thrown by the type initializer for 'DAL.MyModel.InformationContext."} I will be so thankful if someone could help me . Here my source code in the Program.cs:

    //Storing balance data into the database
    using (InformationContext db = new InformationContext())
    {
    db.Balances.Add(new Balance_Model()
    {
    EuroBookingBalance = Bal.ElementAt(0).EuroBookingBalance,
    Id = Bal.ElementAt(0).Id,
    ABI = Bal.ElementAt(0).Account.ABI,
    BBAN = Bal.ElementAt(0).Account.BBAN,
    CIN = Bal.ElementAt(0).Account.CIN,
    Currency = Bal.ElementAt(0).Account.Currency,
    Description = Bal.ElementAt(0).Account.Description,
    Number = Bal.ElementAt(0).Account.Number,
    AccountId = Bal.ElementAt(0).Account.Id,
    Date = Bal.ElementAt(0).Date.ToString(),
    AccountHolder = Bal.ElementAt(0).Account.AccountHolder,
    CAB = Bal.ElementAt(0).Account.CAB,
    CurrencyBookingBalance = Bal.ElementAt(0).CurrencyBookingBalance

                });
    
                db.Transactions.Add(new Transaction\_Model()
                {
                    ABI = tra.ElementAt(0).Account.ABI,
                    AccountDescription = tra.ElementAt(0).Account.Description.ToString(),
                    Amount = tra.ElementAt(0).Amount,
                    TransactionDate = tra.ElementAt(0).TransactionDate.ToString(),
                    AdditionalDescription = tra.ElementAt(0).AdditionalDescription,
                    AccountHolder = tra.ElementAt(0).Account.AccountHolder,
                    CAB = tra.ElementAt(0).Account.CAB,
                    Currency = tra.ElementAt(0).Currency,
                    Description = tra.ElementAt(0).Description,
                    Id = tra.ElementAt(0).Id,
                    Number = tra.ElementAt(0).Account.Number.ToString(),
                    ValueDate = tra.ElementAt(0).ValueDate.ToString(),
                    AbiReason = tra.ElementAt(0).AbiReason.ToString()
    
    D 1 Reply Last reply
    0
    • S sifi mohamed amine

      I need to add deserialized data from xml file to the model in Entity Framework cod efirst in order to generate my database in SQL Server CE. The problem was that I have two tables , the first was done without problems but when I added the second model I got an exception : {"Exception has been thrown by the type initializer for 'DAL.MyModel.InformationContext."} I will be so thankful if someone could help me . Here my source code in the Program.cs:

      //Storing balance data into the database
      using (InformationContext db = new InformationContext())
      {
      db.Balances.Add(new Balance_Model()
      {
      EuroBookingBalance = Bal.ElementAt(0).EuroBookingBalance,
      Id = Bal.ElementAt(0).Id,
      ABI = Bal.ElementAt(0).Account.ABI,
      BBAN = Bal.ElementAt(0).Account.BBAN,
      CIN = Bal.ElementAt(0).Account.CIN,
      Currency = Bal.ElementAt(0).Account.Currency,
      Description = Bal.ElementAt(0).Account.Description,
      Number = Bal.ElementAt(0).Account.Number,
      AccountId = Bal.ElementAt(0).Account.Id,
      Date = Bal.ElementAt(0).Date.ToString(),
      AccountHolder = Bal.ElementAt(0).Account.AccountHolder,
      CAB = Bal.ElementAt(0).Account.CAB,
      CurrencyBookingBalance = Bal.ElementAt(0).CurrencyBookingBalance

                  });
      
                  db.Transactions.Add(new Transaction\_Model()
                  {
                      ABI = tra.ElementAt(0).Account.ABI,
                      AccountDescription = tra.ElementAt(0).Account.Description.ToString(),
                      Amount = tra.ElementAt(0).Amount,
                      TransactionDate = tra.ElementAt(0).TransactionDate.ToString(),
                      AdditionalDescription = tra.ElementAt(0).AdditionalDescription,
                      AccountHolder = tra.ElementAt(0).Account.AccountHolder,
                      CAB = tra.ElementAt(0).Account.CAB,
                      Currency = tra.ElementAt(0).Currency,
                      Description = tra.ElementAt(0).Description,
                      Id = tra.ElementAt(0).Id,
                      Number = tra.ElementAt(0).Account.Number.ToString(),
                      ValueDate = tra.ElementAt(0).ValueDate.ToString(),
                      AbiReason = tra.ElementAt(0).AbiReason.ToString()
      
      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      And the exception message would be .....?? Without it, there's nothing anyone can do to help you.

      A guide to posting questions on CodeProject

      How to debug small programs
      Dave Kreskowiak

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups