A: 

I don't know LLBLGen, but I believe you could solve your problem this way, by introducing an interface to hold the type parameter:

public interface DTOProvider<T> where T : CommonDTOBase {
    public T ToDTO();
}

And then for your entity classes, do this:

public partial class PersonEntity : CommonEntityBase, DTOProvider<PersonDTO> {
    public PersonDTO ToDto() { return new PersonDTO(); }
}

Because partial classes can introduce different interfaces, this works. The only sadness is that a cast is required to get access to the method via the base type:

public void DoSomethingWithDTO<T>(CommonBaseEntity entity)
        where T : CommonDTOBase {
    T dto = ((DTOProvider<T>) entity).ToDTO();
    ...
}

Of course, you can call ToDTO directly without the cast when you have a reference of one of the entity derived types:

public void DoSomethingWithPersonDTO(PersonEntity entity)
{
    PersonDTO dto = entity.ToDTO();
    ...
}

If you are using .NET Framework 4, you can use generic variance to make the DTOProvider interface easier to use from code that just cares about working with CommonDTOBase by declaring the DTO type covariant:

public interface DTOProvider<out T> where T : CommonDTOBase {
    public T ToDTO();
}

(Notice the 'out'.) Then your DoSomethingWithDTO method doesn't need the type parameter:

public void DoSomethingWithDTO(CommonBaseEntity entity) {
    CommonDTOBase dto = ((DTOProvider<CommonDTOBase>) entity).ToDTO();
    ...
}

It is tempting to try and declare : CommonBaseEntity, DTOProvider<T> on the CommonBaseEntity partial class. Unfortunately that doesn't work, because when the partial definitions are merged the type parameter is carried over and your CommonBaseEntity type ends up being a generic type, which it looks like is what got you into a bind in the first place.

Dominic Cooney
With this approach, where does `CommonBaseEntity` get its definition for `ToDto()`? If it inherits using `: DTOProvider<CommonDTOBase>`, then we run into my original problem of not being able to change return types, and if it inherits using `: DTOProvider<T>`, then we have to incorporate generics into `CommonBaseEntity`.
cmptrgeekken
+3  A: 

Instead of:

public abstract partial class CommonEntityBase {
    public abstract CommonDTOBase ToDto();
}

public partial class PersonEntity : CommonEntityBase {
    public override PersonDTO ToDto(){ return new PersonDTO(); }
}

Why are you not just returning a DTO like this:

public abstract partial class CommonEntityBase {
    public abstract CommonDTOBase ToDto();
}

public partial class PersonEntity : CommonEntityBase {
    // changed PersonDTO to CommonDTOBase
    public override CommonDTOBase ToDto(){ return new PersonDTO(); }
}

I think that's more idiomatic for OO code. Is there a reason you need to know the exact type of the DTO?

Porges