Why my DataAccess Class need to be marked as serializable?

Why my DataAccess Class need to be marked as serializable?

Old forum URL: forums.lhotka.net/forums/t/10117.aspx


ddredstar posted on Monday, February 28, 2011

I seperate my data access in an Assemble( just ADO.NET things)

when i call BeginSave like bellow

 

 

Client.BeginSave((s,o) => {

 

 

 

if(o.Error==null

)

Client = o.NewObject

 

 

 

as MyProj.Business.Client.Client

;

 

there is an error happening says:

Type 'MyProj.DataAccess.Client.ClientDAO' in Assembly 'MyProj.DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

please help me, Thanks

ajj3085 replied on Monday, February 28, 2011

Probably because your BO has a field where it is holding a reference to your ClientDAO object.  I'd remove the field, you normally wouldn't need to keep the DAOs around outside of the DP_xyz methods (those should also be the only places your code uses the ClientDAO object).

ddredstar replied on Monday, February 28, 2011

Yes, you are right, i have a field of ClientDAO in my BusinessObject.

What if there are other reasons that i must keep my DataAccess in a seperate assemble, how to resolve it? Thanks!

ddredstar replied on Monday, February 28, 2011

I create the DataAccess instance in DP_xxx to resolve this. but i 'm not clear if this is the correct way.

Thanks!

ajj3085 replied on Tuesday, March 01, 2011

Sorry, I'm not sure I understand what you're asking.  Are you asking what if you had to have a reference to your DAO outside of the data portal methods? Or something else?

JonnyBee replied on Wednesday, March 02, 2011

The DAO object fields should have the NonSeralilaized and NotUndoable attributes so that it will not be part of serialization or undo operations.

You may also look at the MEF samples for Repository and ObjectFactory data access in http:\\cslacontrib.codeplex.com to show a possible way of injecting the data access classes into BO's.

 

Copyright (c) Marimer LLC