Re: Question about data layer

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Here is a ModelBase interface that alloows you to do that even over SOAP.
You may well ask why is this in the model? Well that is because I have
created these everywhere and IMHO this functionality is best here.


public interface IModelBase<TModelType>

{

int Id { get; set; }

DateTime DateArchived { get; set; }

TModelType UnderlyingValues { get; set; }

}

public interface IModelConcurrency

{

void PopulateUnderlyingValues();

void UndoChanges();

bool IsNew();

bool IsDirty(DataLoadingEnum dataLoadingLevel, int level);

bool IsArchive();

bool IsDirty(DataLoadingEnum dataLoadingLevel);

bool HasChanges

{

get;

set;

}

bool HasCompositeChanges

{

get;

set;

}

}



To get you going these are refection based but you can create an abstract
class and make each method virtual to allow you to ovveride in each to
remove the perfromance hit of reflection. but these reletive based methods
are good for prototypes. You DAL calls populate after it has populated the
object. Whan you call Save you identify if isNew, isDirty, Isarchive/delete.
I will not give you all the code because you need to understand and probably
do it your own way Data Access is personal and each has their opinion, but
hopefully it gives you an idea of how the model can support the DAL, and
still be useable over SOAP, rather than methods in properties which in my
opinion do not work as well but thats just my opinion and any way that work
well is fine.

public abstract class ModelBase<TModelType> : IModelBase<TModelType>,
IModelConcurrency where TModelType : ModelBase<TModelType>, new()

{

public virtual void PopulateUnderlyingValues()

{

Type type = typeof(TModelType);

//Get a list of public properties

if (UnderlyingValues == null)

UnderlyingValues = new TModelType();

PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance |
BindingFlags.Public);

//for each property populate the corresponding underlying value from the
object property

foreach (PropertyInfo property in properties)

{

if (property.CanWrite && property.Name != "UnderlyingValues")

{

property.SetValue(UnderlyingValues, property.GetValue(this, null), null);

}

}

}

public bool IsNew()

{

if (this.UnderlyingValues == null)

return true;

else

return false;

}

}


.



Relevant Pages

  • Re: Factory method question
    ... and rather to an interface or abstract class. ... my suggestion means you'd be programming to concrete classes. ... bool IsMatch; ... database with a unique ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Role Based Security
    ... I decided to go to a RIGHTS based model. ... The below interface has met my needs, ... bool IsInAnyRole; ... ISecurityRoleCollection AllRoles //and ISecurityRole is just a Guid ...
    (microsoft.public.dotnet.framework)
  • Re: creating a _simple_ fine grained user based security system
    ... I'd create an interface, something like this ... bool CanEditReservation(User user, Reservation reservation); ... Another benefit of this is that when you write your unit tests you can create a mock IUserPermissionService and register it in the service provider in order to control the outcome of the test. ...
    (microsoft.public.dotnet.languages.csharp)
  • Exposing .NET Events in COM
    ... I have developed a C++ class that implements the source interface my .NET class exposes for events ... I Instantiate the event sink succesfully. ... bool ProcessOutgoingTransaction; ... Then I used COM in my Visual C++(Dialog based application to use the NET OBJECT: ...
    (microsoft.public.dotnet.framework.interop)
  • Exposing .NET Events in COM
    ... I have developed a C++ class that implements the source interface my .NET class exposes for events ... I Instantiate the event sink succesfully. ... bool ProcessOutgoingTransaction; ... Then I used COM in my Visual C++(Dialog based application to use the NET OBJECT: ...
    (microsoft.public.dotnet.framework.interop)