Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old October 29th, 2013, 05:11 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default error info

Same error with tolist().

I should add that when I use EF6 (as for this test), if I leave the config box checked, the process of creating the .tt files, etc fails. So, I ran it once with the box checked to get the connection string (and then I had to change it's name to "entities"). I ran it a second time to with the box unchecked and then went forward from there.

The debugger always points to end of the query line. Here is the error detail:

Code:
System.Data.Entity.Core.MetadataException was unhandled by user code
  HResult=-2146232007
  Message=Unable to load the specified metadata resource.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
       at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
       at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
       at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
       at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry)
       at System.Data.Entity.Core.Metadata.Edm.MetadataCache.SplitPaths(String paths)
       at System.Data.Entity.Core.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
       at System.Data.Entity.Core.Common.Utils.Memoizer`2.Result.GetValue()
       at System.Data.Entity.Core.Common.Utils.Memoizer`2.Evaluate(TArg arg)
       at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetArtifactLoader(DbConnectionOptions effectiveConnectionOptions)
       at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions effectiveConnectionOptions)
       at System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace()
       at System.Data.Entity.Core.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
       at System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory)
       at System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection)
       at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
       at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
       at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
       at System.Data.Entity.Internal.InternalContext.Initialize()
       at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
       at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
       at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
       at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
       at System.Linq.Queryable.Select[TSource,TResult](IQueryable`1 source, Expression`1 selector)
       at _Default.GridView1_GetData() in C:\WebDevLapTest\ModelFromDB6\Default.aspx.vb:line 12
  InnerException:
Here is my config file as it stands now:

Code:
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.1">
      <assemblies>
        <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
      <buildProviders>
        <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
      </buildProviders>
    </compilation>
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
  <connectionStrings>
    <add name="Entities" connectionString="metadata=res://*/App_Code.tinyModel.csdl|res://*/App_Code.tinyModel.ssdl|res://*/App_Code.tinyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxx\sqlexpress;initial catalog=TinyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
I seems like something in my overall procedure is screwed up.

Last edited by daveharney; October 29th, 2013 at 07:00 PM..
Reply With Quote
  #12 (permalink)  
Old October 29th, 2013, 06:13 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can you send me a zipped copy of the site and database (including the bin folder)? Then I'll take a look and see if I can figure it out.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
daveharney (October 29th, 2013)
  #13 (permalink)  
Old October 29th, 2013, 07:46 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default zip files

I sent the zip to your email address from a year and a half ago. Please let me know if you get it OK - otherwise I'll go through your blog.

"Or maybe not ;-) Concepts from that book are very different from the stuff in the Beginning book. I would recommend staying close to my Beginning ASP.NET book and make things work with EF 6 and VS 2013. You'll need to learn a million new concepts if you want to switch to the n-layered approach described in my e-book...."

I agree - I had that thought when I first saw that series on your blog earlier. In my prior life, when I was designing business systems, they were typically 3 tier with Oracle on a large Unix machine, C/C++ on another Unix box for business logic, and then a PC user frontend or realtime automation machines. Sometimes for millions of transactions a day. Now, I just ride my bicycle and enjoy programming just for the fun of it - I didn't get a chance to do much actual coding in my work days.
Reply With Quote
  #14 (permalink)  
Old October 30th, 2013, 07:26 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Looks like you mixed up a few different attempts. In general, just follow the wizard when it offers to store the connecting string in web.config and it will do the right thing. There really isn't a reason not to store it in web.config.

In your case, it looks like you used a connection string from a model called tinyModel against a model called Model. The fix is easy: just remove the word tiny (twice) from your connection string:

Code:
<add name="Entities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.tinyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=hplap\sqlexpress;initial catalog=TinyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
That fixes the EF issue but now you have a broken query. (ToList doesn't result in an IQueryable). There are two fixes:

1. Return an IEnumerable. This makes it more difficult to page and sort, but for simple display this is the fastest solution:

HTML Code:
Public Function GridView1_GetData() As IEnumerable(Of TestTable1)
Using myentities As New Entities()
  Dim myquery = From mytable In myentities.TestTable1 Select mytable
  Return myquery.ToList()
End Using
End Function
Alternatively don't use a Using block. In that case, it's a good idea to create a class level variable for the entities, and get rid of it in Unload, like this:

Code:
Imports System.Linq

Partial Class _Default
    Inherits System.Web.UI.Page

  Private myEntities As New Entities()

  Public Function GridView1_GetData() As IQueryable(Of TestTable1)
    Return From mytable In myEntities.TestTable1 Select mytable 
  End Function

  Protected Sub Page_OnUnload(sender As Object, e As EventArgs) Handles Me.Unload
    If myEntities IsNot Nothing Then
      myEntities.Dispose()
    End If
  End Sub

End Class
If you want to support sorting (using AllowSorting on the GridView) you need to sort the code initially in the query, like this:

Code:
Imports System.Linq

Partial Class _Default
    Inherits System.Web.UI.Page

  Private myEntities As New Entities()

  Public Function GridView1_GetData() As IQueryable(Of TestTable1)
    Return From mytable In myEntities.TestTable1 Select mytable Order By mytable.FirstField
  End Function

  Protected Sub Page_OnUnload(sender As Object, e As EventArgs) Handles Me.Unload
    If myEntities IsNot Nothing Then
      myEntities.Dispose()
    End If
  End Sub

End Class
Hope this helps, but let me know if it doesn't.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
daveharney (October 30th, 2013)
  #15 (permalink)  
Old October 30th, 2013, 10:19 AM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Works 100%

Hi Imar,

Thank you very much!! I also created a new iteration of this exercise that resulted in a proper display of the grid with no errors - it took about 3 minutes from start to finish. Amazing what one can do with proper guidance!

BTW, for other newbies reading this, when adding the "selectmethod" to the girdview, just let VS create the codebehind by clicking "create new method" - very cool.

Now, I can understand the bigger picture here. Before, I just couldn't get a sense of direction and was my own worst enemy by thrashing around and mixing things up. I also learned that reading how-to articles written prior to EF6 can be dangerous to one's health when operating in this new environment. This EF6 paradigm is much cleaner and more logical to program. I have lots of questions about "how it works" and other code variations but that can wait for your new book. Now that I won't be wasting your time, maybe you can get it published earlier

Thanks again for your help and patience.
Reply With Quote
  #16 (permalink)  
Old October 30th, 2013, 11:19 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I also created a new iteration of this exercise that resulted in a proper display of the grid with no errors
Excellent, glad you got it working.

Quote:
when adding the "selectmethod" to the girdview, just let VS create the codebehind by clicking "create new method" - very cool.
Indeed; I really like that feature. It also works for the insert, update and delete methods. It only works for smart data controls like the GridView but not for the DropDownList for example.

Quote:
Thanks again for your help and patience.
You're welcome.

Cheers.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #17 (permalink)  
Old November 24th, 2013, 01:15 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Quick Question

Hi Imar,

While waiting for your new book , I'm using VS2013 and generally doing OK with your current book. But, I've one problem that is a real pain and googling about hasn't helped: WSAT is not in VS2013 and you don't cover the API method. I'm making some security changes for my site upgrade and need this capability. Is there a substitute or is this a whole new topic for your new book?

As I still have VS 2010, I'm thinking that I can follow your current book in a little temp website that uses the same DB in the new SQL Svr 2012. This should push the changes into the DB and I can check the web.config and copy any changes there to my actual website. Is this a good strategy?
Reply With Quote
  #18 (permalink)  
Old November 25th, 2013, 10:50 AM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Using VS 2010

Quote:
Originally Posted by daveharney View Post
As I still have VS 2010, I'm thinking .....Is this a good strategy?
I found it not very easy to change the provider configuration stuff and gave up on that strategy.

I did what you suggested in your book and went to the "Professional" book and lifted some .aspx pages to add roles and assign users to roles. Seems to be working OK.

Getting WSAT into VS 2013 apparently can be done with a hack - but I gave up on that also - too complicated. Hope your new book deals with this issue.
Reply With Quote
  #19 (permalink)  
Old November 25th, 2013, 03:55 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

>> Hope your new book deals with this issue.

It does by using the "hack" as there currently is no other way to do it.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #20 (permalink)  
Old November 25th, 2013, 04:14 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default WSAT

Quote:
Originally Posted by Imar View Post
using the "hack"
Well, I'm sure you'll explain it better than what I found.

I would think someone has an opportunity here to put together a basic GUI somewhat along the lines of what is in the Professional book. Having read some of the comments while searching for info on this, I'm pretty sure it would be much appreciated.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP, Original PHP, Mysql and Apacher versions used in the book Sam321 BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 1 August 12th, 2012 07:07 AM
Different Versions of IE South Side Rob BOOK: CSS Instant Results 1 February 26th, 2009 06:05 PM
VS versions??? SKhna Javascript 1 February 4th, 2008 03:27 PM
Book Versions MER78 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 September 24th, 2004 02:56 PM
Java Versions? maayub J2EE 4 August 22nd, 2003 05:29 AM



All times are GMT -4. The time now is 11:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.