 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

October 29th, 2013, 05:11 PM
|
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
|
|
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="data source=xxx\sqlexpress;initial catalog=TinyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" 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..
|
|

October 29th, 2013, 06:13 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

October 29th, 2013, 07:46 PM
|
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
|
|
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.
|
|

October 30th, 2013, 07:26 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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="data source=hplap\sqlexpress;initial catalog=TinyDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" 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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

October 30th, 2013, 10:19 AM
|
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
|
|
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.
|
|

October 30th, 2013, 11:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

November 24th, 2013, 01:15 PM
|
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
|
|
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?
|
|

November 25th, 2013, 10:50 AM
|
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
|
|
Using VS 2010
Quote:
Originally Posted by daveharney
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.
|
|

November 25th, 2013, 03:55 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
>> 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
|
|

November 25th, 2013, 04:14 PM
|
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
|
|
WSAT
Quote:
Originally Posted by Imar
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.
|
|
 |
|