Instantiation of entity results in db access

Posts   
 
    
MaxManu
User
Posts: 7
Joined: 02-Feb-2009
# Posted on: 27-Jul-2009 16:42:10   

Hi,

Don't know where else to post this so im trying in general,

I have a line of code which is as follows:

UserEntity = new UserEntity();

When this runs a sql statement is sent to the db (seen in profiler) where it tries to fetch data from a related table (UserAffiliation) and none of the other related tables.

This must be wrong, I would of thought that using the default constructor would not result in any db access??

Any help or insight on this would be most helpful.

Running c# 2.0 selfservice

Regards Manuel Fraga iCODE AS

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jul-2009 04:52:16   

Hi Manuel,

Some questions:

  • Are you 100% sure that line fires the SQL?
  • Please post the DDL of that table (to see the PK, etc.)
  • Is that entity involved in inheritance?
  • Do you have custom code inside the entity. Have you modified some entity behavior?
  • Exact LLBLGen Runtime Library version? (http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7722)
David Elizondo | LLBLGen Support Team
MaxManu
User
Posts: 7
Joined: 02-Feb-2009
# Posted on: 28-Jul-2009 10:03:40   

Hi,

Thanks for the reply,

  1. I am a 100% certain the SQL is fired by the statement, I am the only user of the SQL server and running a default trace and halting execution straight before and immediately after the statement generates the following output in profiler:

exec sp_executesql N'SELECT [eFeide].[dbo].[UserAffiliation].[ID] AS [Id], [eFeide].[dbo].[UserAffiliation].[User_ID] AS [UserId], [eFeide].[dbo].[UserAffiliation].[AffiliationType_ID] AS [AffiliationTypeId], [eFeide].[dbo].[UserAffiliation].[IsPrimary] FROM [eFeide].[dbo].[UserAffiliation] WHERE ( ( [eFeide].[dbo].[UserAffiliation].[User_ID] = @UserId1))',N'@UserId1 nvarchar(20)',@UserId1=N''

and when I check the object in VS I can see that the AlreadyFetchedUserAffiliation property is set to true.

  1. See attachment for DDL script.

  2. No inheritance.

  3. I have extended to code of the class using a separate code file ie partial class, but I have only added a custom method and implemented an override on ValidateEntity.

  4. Runtime version is 2.6.8.903.

Best Regards

Manuel

Attachments
Filename File size Added on Approval
DDL.txt 2,872 28-Jul-2009 10:04.01 Approved
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Jul-2009 10:53:43   
  1. I have extended to code of the class using a separate code file ie partial class, but I have only added a custom method and implemented an override on ValidateEntity.

Please attach this file.

  1. Runtime version is 2.6.8.903.

A side issue....this is a very old build.

Are you using adapter or selfservicing? Do you have fields mapped onto related fields?

MaxManu
User
Posts: 7
Joined: 02-Feb-2009
# Posted on: 28-Jul-2009 11:00:10   
  1. Attached.

  2. Attached image of relation settings from llblgen.

Regards

Manuel Fraga

Attachments
Filename File size Added on Approval
User.cs 6,394 28-Jul-2009 11:00.46 Approved
MaxManu
User
Posts: 7
Joined: 02-Feb-2009
# Posted on: 28-Jul-2009 11:02:09   

simple_smile max one att pr post so here's the image file

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Jul-2009 11:16:27   

Walaa wrote:

Are you using adapter or selfservicing?

The fetch might be caused by a watch in the debugger window? The code itself doesn't fetch any related entities, in fact it doesn't fetch anything.

MaxManu
User
Posts: 7
Joined: 02-Feb-2009
# Posted on: 28-Jul-2009 11:54:00   

Your a genius !simple_smile ,

It was an old watch expression causing the retrieve, had totally forgotten about it. Ahh typically the "hardest" problems have the most obvious solutions . . .

Thanks for the time and effort!

Best regards

Manuel Fraga

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Jul-2009 12:41:27   

Your a genius !

I shouldn't take the credit for myself, actualy that was Frans's hint.

Anyway we are glad this issue was sorted.

Good luck.