Storing deserialized data into SQL Server Ce using Entity Framework code first
-
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()
-
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()
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