Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 Display Modes
  #1 (permalink)  
Old January 6th, 2012, 04:11 PM
Authorized User
Points: 224, Level: 4
Points: 224, Level: 4 Points: 224, Level: 4 Points: 224, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old January 6th, 2012, 08:00 PM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,050
Thanks: 80
Thanked 1,581 Times in 1,558 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!
Reply With Quote
  #3 (permalink)  
Old January 14th, 2012, 02:20 PM
Authorized User
Points: 224, Level: 4
Points: 224, Level: 4 Points: 224, Level: 4 Points: 224, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #4 (permalink)  
Old January 15th, 2012, 07:59 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,050
Thanks: 80
Thanked 1,581 Times in 1,558 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!
Reply With Quote
Reply


Thread Tools
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
Entity Framework Code First 4.1 JackHerr BOOK: Professional ASP.NET MVC 3 3 September 16th, 2011 06: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 10: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 02:32 PM



All times are GMT -4. The time now is 12:24 AM.


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