none
Using the ADO.NET DBContext Generator RRS feed

  • Question

  • I downloaded and tried to run Julie Lerman’s application, "Building an MVC 3 App with Database First and Entity Framework 4.1," but it wouldn’t open and I got the error message, "System.Data.EntityException was unhandled by user code

    Message=The underlying provider failed on Open" on the BlogController.vb at line 9, which reads -- Return View(db.Blogs.ToList()).

    Then I began to construct the app from Julie’s tutorial and got to where we are to generate the classes from ADO.NET DbContext Generator. When I did this the new folders Model1.Context.tt and Model1.tt where generated, but the Model1.Context.vb and Blog.vb, Comment.vb, Model1.vb and Post.vb were not generated. When I chose to use the DbContext Generator I got a warning message that using this generator could damage my computer, but I did use it; does this suggest or indicate anything?

    I suspect that the failure is because the VS 2010 Express version that I am using doesn’t support these features, or is there another explanation?  I am also using Visual Basic to code by.


    Robert Agans
    Friday, October 7, 2011 8:54 PM

Answers

  • Robert, you said

    "the new folders Model1.Context.tt and Model1.tt where generated, but the Model1.Context.vb and Blog.vb, Comment.vb, Model1.vb and Post.vb were not generated."

    my guess is that you just don't see the vb files becuase by default they are hidden. If you are working with the Visual Basic project, you might need to click Show All Files in Solution Explorer to see all files in the project.

    Also, can you just try creating a simple console app from scratch just to see if the EF works for you. You can follow one of these walkthroughs:

    if you have an existing db - http://msdn.microsoft.com/en-us/library/gg696166(VS.103).aspx

    if you are starting with code - http://msdn.microsoft.com/en-us/library/gg696189(VS.103).aspx  

     

    Please, let us know if  that worked for you.

    For additional help on EF 4.1 go here: http://msdn.microsoft.com/en-us/library/gg696172(VS.103).aspx

    Thank you,

    Julia 

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by BobOfCalif Tuesday, October 11, 2011 8:52 PM
    Tuesday, October 11, 2011 6:56 AM
    Moderator
  • Hi Bob,

    Thanks for your feedback.

    I'm glad to hear that you are interested in Entity Framework. When you add the same edmx file in your project, the connection string will be automatically appended "1". If you have deleted the old edmx file, you should delete the connection string from (web/app).config file. I think this link is good for you: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx

    BTW, the team blogs introduce a lot of new features!

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by BobOfCalif Tuesday, October 11, 2011 8:52 PM
    Tuesday, October 11, 2011 9:16 AM
    Moderator
  • Greetings to both Alan and Julia,

    I followed through with Julie Lerman’s tutorial and everything is working fine. I had to deviate from Julie’s tutorial because one of the boxes she said to check was not available to me, but when I used what was available everything was coded for me and it worked immediately. I will use this new app and Julie’s tutorial as a bases from which to work and experiment.

    Thank you both very much, for your help and encouragement,

    Bob


    Robert Agans
    Tuesday, October 11, 2011 8:54 PM

All replies

  • Hi Robert,

    Could you use Database First to add entities to your edmx? Please ensure the connection string is right. Entity Framework just relate to .NET Framework RTM. I think you can try to reinstall EF4.1(http://www.microsoft.com/download/en/details.aspx?id=8363)

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 10, 2011 8:36 AM
    Moderator
  • Hi Alan,

    Thanks for responding to my request. Just to help you better understand my situation, I’m not a professional or developer. I’m retired and 75 years old, and use several of Microsoft’s NET Framework platforms, some on my website and some just for fun and enjoyment. I’m using Windows 7 Professional, VS 2010 Express, Windows forms and WPF, Web forms and MVC 3, LINQ to SQL and Entities Framework, and I especially like WPF, MVC and Entities Framework. The only one that I am having trouble with is Entities Framework. If I could just get Julie Lerman’s application, Building an MVC 3 App with Database First and Entity Framework 4.1 working so I could analyze and understand it, I think that would satisfy my immediate needs. Julie explained that ADO.NET DbContext Generator was a simplified version of Entity Framework.

    Following your instructions, I redownloaded EF 4.1 and got the same results as in my original entry. Then I checked and found that I could add a new entity. Then I checked and found that I did have a connection to the BlogData.mdf, in fact I had two connections.

    <add name="BlogDataEntities" connectionString="metadata=res://*/Models.BlogModel.csdl|res://*/Models.BlogModel.ssdl|res://*/Models.BlogModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Documents\BlogData.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

    and BlogDataEntities1, and I still get the same results.

    Bob


    Robert Agans
    Monday, October 10, 2011 9:04 PM
  • Robert, you said

    "the new folders Model1.Context.tt and Model1.tt where generated, but the Model1.Context.vb and Blog.vb, Comment.vb, Model1.vb and Post.vb were not generated."

    my guess is that you just don't see the vb files becuase by default they are hidden. If you are working with the Visual Basic project, you might need to click Show All Files in Solution Explorer to see all files in the project.

    Also, can you just try creating a simple console app from scratch just to see if the EF works for you. You can follow one of these walkthroughs:

    if you have an existing db - http://msdn.microsoft.com/en-us/library/gg696166(VS.103).aspx

    if you are starting with code - http://msdn.microsoft.com/en-us/library/gg696189(VS.103).aspx  

     

    Please, let us know if  that worked for you.

    For additional help on EF 4.1 go here: http://msdn.microsoft.com/en-us/library/gg696172(VS.103).aspx

    Thank you,

    Julia 

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by BobOfCalif Tuesday, October 11, 2011 8:52 PM
    Tuesday, October 11, 2011 6:56 AM
    Moderator
  • Hi Bob,

    Thanks for your feedback.

    I'm glad to hear that you are interested in Entity Framework. When you add the same edmx file in your project, the connection string will be automatically appended "1". If you have deleted the old edmx file, you should delete the connection string from (web/app).config file. I think this link is good for you: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx

    BTW, the team blogs introduce a lot of new features!

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by BobOfCalif Tuesday, October 11, 2011 8:52 PM
    Tuesday, October 11, 2011 9:16 AM
    Moderator
  • Hi Julia,

    Thank you for your input. I went back and started Julie Lerman’s tutorial from the beginning again to see if it reacted the same way. This time when I used the DB Context Generator the expander arrows where there along with the VB files, I didn’t have to use expand all files; I have no idea why it reacted differently, but it could be because I removed the two connection strings that I discovered in the web config file. I will continue with her tutorial and see how far I can get before I run into some more trouble; I have to use a translator from C# to VB that I found on the internet. As soon as I find if I can complete and use the application I will let you know.

    And thanks for the links you provided, I looked at them briefly and think the gg696166 one will be especially helpful. Again thank you for your helpful input.

    Bob


    Robert Agans
    • Edited by BobOfCalif Tuesday, October 11, 2011 7:08 PM
    Tuesday, October 11, 2011 7:03 PM
  • Hi Alan,

    Thank you for helping me! As I replied to Julia Kornich above, I went back to the project I was constructing from Julie Lerman’s tutorial and started over again. As you suggested I first deleted the previous connection strings in the web config file, and this time when I used the DB Context Generator the expander arrows where there along with the VB files. I will continue with Julie’s tutorial and see if I can complete and use it, when I find out I will let both you and Julia know what I have discovered.

    Thank you for the informative link, I tried to use it before but run into some sort of trouble, but I will try again because I want to get EF’s simple version working with WPF also.

    Bob


    Robert Agans
    Tuesday, October 11, 2011 7:36 PM
  • Greetings to both Alan and Julia,

    I followed through with Julie Lerman’s tutorial and everything is working fine. I had to deviate from Julie’s tutorial because one of the boxes she said to check was not available to me, but when I used what was available everything was coded for me and it worked immediately. I will use this new app and Julie’s tutorial as a bases from which to work and experiment.

    Thank you both very much, for your help and encouragement,

    Bob


    Robert Agans
    Tuesday, October 11, 2011 8:54 PM