Answered DbContext does not retrieve SqlCeBulkCopy copied records

  • Saturday, December 08, 2012 7:31 AM
     
      Has Code
    Hello, I am using EF with DbContext. I managed to bulk copy rows into an entity named BusinessEntity, but the DbContext just won't retrieve the records even when I can see the records in the table. Any suggestions?
    EntityConnection econn = (EntityConnection)((IObjectContextAdapter)dbContext).ObjectContext.Connection;
    
                        econn.Open();
    
                        using (SqlCeBulkCopy bc = new SqlCeBulkCopy((SqlCeConnection)(econn.StoreConnection)))
                        {
                            #region ADD TO BusinessEntity
                            bc.DestinationTableName = "BusinessEntity";
                            bc.ColumnMappings.Add("IDN", "IDN");
                            bc.ColumnMappings.Add("RowGuid", "RowGuid");
                            bc.ColumnMappings.Add("Remarks", "Remarks");
                            bc.WriteToServer(individualsForBulkImport); 
                            #endregion
    
    ==>This line                        var businessEntities = dbContext.BusinessEntities.ToList();
                        }
    
                        econn.Close();

    Thanks, cp

    • Edited by cp.net Saturday, December 08, 2012 9:20 AM
    • Edited by cp.net Saturday, December 08, 2012 9:21 AM
    • Moved by Allen Li - MSFT Monday, December 10, 2012 3:15 AM (From:SQL Server Compact)
    •  

All Replies

  • Monday, December 10, 2012 3:14 AM
     
     

    Hi cp.net,

    Thank you for your question. 

    Since this issue is related to ADO.NET Entity Framework, I will move this thread to ADO.NET Entity Framework forum. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 

    Thank you for your understanding and support.


    Allen Li
    TechNet Community Support

  • Monday, December 10, 2012 9:40 AM
    Moderator
     
     

    Hi cp.net,

    Welcome to the MSDN forum.

    I tested your code with SqlBulkCopy on my side. I get the entities successfully. I will test the assembly for SqlCeBulkCopy to check this problem.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Wednesday, December 12, 2012 8:27 AM
    Moderator
     
     

    Hi cp.net,

    I tested your problem via SQL Compact database, and got the results successfully. I am using Visual Studio 2010 SP1 with SQL Compact 4.0. The target of solution is .NET Framework 4.0. Could you please let me know whether you are using ErikEJ.SqlCe40.dll? I am using ErikEJ.SqlCe40 (version 2.1.5.1) and System.Data.SqlServerCe.dll (version 4.0.0.0).

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Thursday, December 13, 2012 3:22 AM
     
     Answered

    Hello Alexander,

    Thank you for the response. I am using VS 2012 with SQL CE 4.0, .NET Framework 4.5, ErikEJ.SqlCe40 (version 2.1.6.0).

    For the time being I am working around the issue by using raw sql with dbContext.Database.SqlQuery which works fine.

    Regards,

    cp