locked
Read Entity Framework Dataset, root type is name mangled RRS feed

  • Question

  • Entity Framework 6

    VS 2013

    I generated a set of tables from my database (database first). When I fill the dataset from the database the root class: SavedScenario is coming in name mangled. Another developer vaguely recalls that there's a switch or setting that can be altered. to change this behavior. This is the code to read in the dataset:

    using (FastData.FASTDataEntities fastData = new FastData.FASTDataEntities(Settings.Default.DBAddress, FastSettingsDB.FastAppUserName, FastSettingsDB.FastAppPassword))
    {
       FastData.SavedScenario scenario = fastData.SavedScenarios.Where(s => s.ID == dlg.SelectedScenario.ID).FirstOrDefault();
    
    ...
    After this executes, when I inspect scenario after this the object type/value is

    {System.Data.Entity.DynamicProxies.SavedScenario_BE80C52CC172E0FF5CA266D06218B00D39359807AD74EEC3C5A2A99433BE973A}

    I need the type to simply be "SavedScenario" The user may may export the object to XML and the DataContractSerializer exports a type name that doesn't import.

    Monday, July 18, 2016 7:04 PM

Answers

All replies

  • I believe one way to do it is...

    Object obj = fastData.SavedScenarios.Where(s => s.ID == dlg.SelectedScenario.ID).FirstOrDefault(); ...

    var scenario = (SavedScenario)obj;

    You might be able to do the cast on the query itself.

    Monday, July 18, 2016 7:15 PM
  • These are the Proxy Types that enable Lazy Loading.  SEe

    Working with Proxies

    David


    David http://blogs.msdn.com/b/dbrowne/

    • Marked as answer by nottoc Monday, July 18, 2016 8:49 PM
    Monday, July 18, 2016 7:19 PM
  • I tried the object casting, that didn't work. Then I tried setting just the ProxyCreationEnabled, that didn't work. Poked around a bit more, saw that Lazy Loading was involved. So, when I set both, that worked.

    using (FastData.FASTDataEntities fastData = new FastData.FASTDataEntities(Settings.Default.DBAddress, FastSettingsDB.FastAppUserName, FastSettingsDB.FastAppPassword))
    {
       fastData.Configuration.LazyLoadingEnabled = false;
       fastData.Configuration.ProxyCreationEnabled = false;
       FastData.SavedScenario scenario = fastData.SavedScenarios.Where(s => s.ID == dlg.SelectedScenario.ID).FirstOrDefault();
    
    ...
    
    

    P.S. Whatever happened to the MSDN edit Post HTML button? I don't know where this font came from, and the only "font" buttons are bold, italic and underline.

    Monday, July 18, 2016 8:48 PM