How can I use TranslationCriteria for Fetching<TranslationList>(translationCriteria)

How can I use TranslationCriteria for Fetching<TranslationList>(translationCriteria)

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


Maikel posted on Tuesday, August 07, 2012

Hi folks,

I've created a criteria class which inherits from the CriteriaBase class...

using

 

 

System;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

using

 

 

 

System.Collections.Generic;

using

 

 

 

Csla;

using

 

 

 

Queaso.Core.Communication.Business.Recources;

namespace

 

 

 

Queaso.Core.Communication.Business

{

[

 

 

Serializable

()]

 

 

 

public class TranslationCriteria : CriteriaBase<TranslationCriteria

>

{

 

 

 

private static readonly PropertyInfo<Guid> TranslationIdProperty = RegisterProperty<Guid

>(c => c.TranslationId);

[System.ComponentModel.

 

 

DataObjectField(true, true

)]

 

 

 

public Guid

TranslationId

{

 

 

 

get { return

ReadProperty(TranslationIdProperty); }

 

 

 

private set { LoadProperty(TranslationIdProperty, value

); }

}

 

 

 

private static readonly PropertyInfo<string> CultureProperty = RegisterProperty<string

>(c => c.Culture);

 

 

 

public string

Culture

{

 

 

 

get { return

ReadProperty(CultureProperty); }

 

 

 

set { LoadProperty(CultureProperty, value

); }

}

 

 

 

private static readonly PropertyInfo<string> ResourceKeyProperty = RegisterProperty<string

>(c => c.ResourceKey);

 

 

 

public string

ResourceKey

{

 

 

 

get { return

ReadProperty(ResourceKeyProperty); }

 

 

 

set { LoadProperty(ResourceKeyProperty, value

); }

}

 

 

 

private static readonly PropertyInfo<string> VirtualPathProperty = RegisterProperty<string

>(c => c.VirtualPath);

 

 

 

public string

VirtualPath

{

 

 

 

get { return

ReadProperty(VirtualPathProperty); }

 

 

 

set { LoadProperty(VirtualPathProperty, value

); }

}

 

 

 

private static PropertyInfo<string> TextProperty = RegisterProperty<string

>(c => c.Text);

 

 

 

public string

Text

{

 

 

 

get { return

ReadProperty(TextProperty); }

 

 

 

set { LoadProperty(TextProperty, value

); }

}

 

 

 

public

TranslationCriteria()

{

}

 

 

 

public TranslationCriteria(string culture, string resourceKey, string virtualPath, string

text)

I have also created a BusinessBase class named TranslationLis

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

using

 

 

 

System;

using

 

 

 

System.Globalization;

using

 

 

 

System.Linq;

using

 

 

 

Csla;

using

 

 

 

Queaso.Core.Communication.Data;

namespace

 

 

 

Queaso.Core.Communication.Business.Recources

{

[

 

 

Serializable

]

 

 

 

public class TranslationList : BusinessListBase<TranslationList, Translation>

{

#region

 

 

 

Business Methods

#endregion

#region

 

 

 

Business and Validation Rules

#endregion

#region

 

 

 

Authorization Rules

#endregion

#region

 

 

 

Factory Methods

 

 

 

public void

LoadTranslations()

{

 

 

 

this.AddRange(DataPortal.Fetch<TranslationList

>());

}

 

 

 

internal void LoadTranslations(TranslationCriteria

translationCriteria)

{

 

 

 

this.AddRange(DataPortal.Fetch<TranslationList

>(translationCriteria));

}

#endregion

#region

 

 

 

Data Acceses

 

 

 

protected void DataPortal_Fetch(TranslationCriteria

criteria)

{

 

 

 

using (var rep = new BaseRepository<Translation

>())

{

 

 

var

translations = rep.FetchObjectByCriteria(criteria);

 

 

foreach (var item in

translations)

Add(

 

 

DataPortal.FetchChild<Translation

>(item));

}

 

}

 

 

 

protected void

DataPortal_Fetch()

{

 

 

 

using (var rep = new BaseRepository<Translation

>())

{

 

 

 

var

translations = rep.FetchAll();

 

 

 

foreach (var item in

translations)

Add(

 

 

DataPortal.FetchChild<Translation

>(item));

}

}

#endregion

}

}

The code that's in bold that's causing a problem...
So I'm using a repository of translations but I want to fetch a TranslationList by passing a translationcriteria parameter...
But the compiler expects a Translation parameter... So how can I use TranslationCriteria for fetching Translations...

My email is mg@queaso.be

JonnyBee replied on Tuesday, August 07, 2012

Is very hard to read your code - please post code in a better format!!!

#1: Use static factory methods (not instance methods) like this:

    #region Factory Methods

    public static TranslationList GetTranslations()
    {
      return DataPortal.Fetch<TranslationList>();
    }


    public static TranslationList GetTranslations(TranslationCriteria translationCriteria)
    {
      return DataPortal.Fetch<TranslationList>(translationCriteria);
    }

    #endregion

    Your code will typically degrade performance by taking the returned list and then add all the items to a new list (which is NOT necessary).

#2: I doubt that you have a Repository based on the business object type?
      If you have a BO Translation and a DAL object Translation you must use namespace to qualify the DAL object in your BO class.

#3: From a "layer" perspective the TranslationCriteria class shown here belong to the "business logic" layer and should not be known to the repository (DAL) code. You may however define an Interface in the DAL code and implement this in TranslationCriteria in order to pass this object to the DAL / Repository code.

Copyright (c) Marimer LLC