Using DataPortal for custom Fetch method

Using DataPortal for custom Fetch method

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


Mark Sulkowski posted on Friday, May 13, 2011

I'm using DataPortal to call server-side factory methods in a data access assembly.

One such method is called like this:

DataPortal.Fetch<SomeRootObject>(criteria);

And there is a corresponding factory object method like this:

public SomeRootObject Fetch(SomeCriteria criteria) { .... }

 

I'd like another method on that factory object like this:

public List<Guid> Fetch(SomeCriteria criteria) { .... }

Can I call it using the DataPortal like this?

DataPortal.Fetch< List<Guid> >(criteria);

Will there be any problems for DataPortal to recognize which method it should call on the data access object?

 

Mark Sulkowski
Linköping, Sweden

RockfordLhotka replied on Friday, May 13, 2011

The data portal implements the same method overload behaviors as .NET.

For example:

 

JonnyBee replied on Friday, May 13, 2011

Yes, in .NET with standard serializers you can use the DataPortal with any serializable object, in Silverlight and Windows Phone the object must be serializable by MobileFormatter and implement one of the Mobile list types like MobileList<T>. You cannot however use the List<T> directly -  you must hav a class in your app toadd the ObjectFactory attribute to.

Your List:

namespace TestApp.Business
{
  [Serializable]
  [ObjectFactory("TestApp.ObjectFactoryDAL.ListClassFactory,TestApp.ObjectFactoryDAL")]
  public class ListClass : List<Guid>
  {
    public static ListClass Fetch(string criteria)
    {
      return Csla.DataPortal.Fetch<ListClass>(criteria);
    }
  }
}

or if in Silverlight or WindowsPhone (will also work on .NET4)

namespace TestApp.Business
{
  [Serializable]
  [ObjectFactory("TestApp.ObjectFactoryDAL.ListClassFactory,TestApp.ObjectFactoryDAL")]
  public class ListClass : MobileList<Guid>
  {
    public static ListClass Fetch(string criteria)
    {
      return Csla.DataPortal.Fetch<ListClass>(criteria);
    }
  }
}

and your DAL:

namespace TestApp.ObjectFactoryDAL
{
  public class ListClassFactory : ObjectFactory
  {
    public object Fetch (string criteria)
    {
      return new ListClass() {Guid.NewGuid()};
    }
  }
}

 

 

 

 

Copyright (c) Marimer LLC