Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : 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
 
Old January 6th, 2012, 04:11 PM
Authorized User
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default Entity Framework Question

Hi Imar,

Got a Q about EF. I'm now working on a personal project where I have a slew of tables (combined with the default asp.net tables, about 15 I guess).

QUESTION: When I create the Entity Model File and I am to include tables, should I include all the tables? Or should I create separate EMF's to "chunk out" sets of tables ... My main concern is load time ... I'm unclear when and how things get loaded ... so from an architectural standpoint, I'm not sure whether to create one EMF and include all the tables there or create multiple EMF's and assign specific tables to each EMF ...

What is the best method to balance function and speed? Thanks.

- Nano
 
Old January 6th, 2012, 08:00 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Most of the time, I use a single edmx as it's much easier to maintain. Beyond 50 or 100 entities, you could consider splitting up the model. For more details:

http://blogs.msdn.com/b/adonet/archi...rk-part-1.aspx
http://blogs.msdn.com/b/adonet/archi...rk-part-2.aspx

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!
 
Old January 14th, 2012, 02:20 PM
Authorized User
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default FirstorDefault()

Hi, thanks for prior reply. I have another question on EF. Got stuck on it last night and this morning, narrowed it down WHERE the error is occurring but I do not understand WHY the error occurs.

Code:
var userCheck = (from check in profileEnt.scAccounts
                                 where check.asp_userId == userID
                                 select check).FirstOrDefault();
When I run this code, I get "Error: Sys.WebForms.PageRequestManagerServerErrorExceptio n: This property cannot be set to a null value."

#1 When I change FirstOrDefault() to Count(), it works: returns "1".

#2 When I remove FirstOrDefault(), it works: returns "System.Data.Objects.ObjectQuery`1[Sc2Saga.scAccount]"

#3 When I remove FirstOrDefault() and use Anonymous Types (e.g., Select new), it works.

When I replace FirstOrDefault() with SingleorDefault(), it fails.

So I see WHERE the error occurs, but I do not understand WHY it fails.

As a workaround, can I use step #2? If so, how do I retrieve the first record in the collection?

Help is greatly appreciated ...

- Nano
 
Old January 15th, 2012, 07:59 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

FirstOrDefault tries to return the first instance in the sequence if there is one, otherwise, it returns null.

The other methods you tried still return a non-null value, even when they are no items in the sequence. In other words, the sequence is empty, but is still a valid object in .NET and not null.

Apparently, the code you're using this on doesn't like null values but can deal with empty sequences.

Hope this helps,

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Entity Framework Code First 4.1 JackHerr BOOK: Professional ASP.NET MVC 3 3 September 16th, 2011 05:15 PM
Entity Framework And MVC geomar BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9 5 January 24th, 2011 04:58 PM
Switching To entity framework luckystar BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 July 31st, 2009 09:52 PM
The BeerHouse and Entity Framework docluv BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 October 3rd, 2008 01:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.