Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating interfaces when return type is entity list
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01505681
Message ID:
01506077
Views:
54
Brian,

>Problem creating interfaces when return type is entity list.
>I'm using mere mortals 3.5
>
>This is going to be a long winded explanation of the problem so please bear with me.
>I have a solution that contains 4 MM business projects and a base class project. My base class has an interface class that is used to access a business object on each of the 4 business projects. Example
>Each of the four business projects have a DataCap business object. These BO’s have some common fields like DLN and also have fields they they do not have in common.
>Each of the four implement the IdataCap interface.
>One of the method calls on the interface is
>Function Fetch_byDLN(ByVal DLN As Int64) As DataSet
>Each of the four implement this method call with no problem.
> Where I’m running into problems is creating interface calls the return entity lists. If I wanted the above method call to return an entity list rather than a dataset how would I set that up?
>Function GetEntityList_byDLN(ByVal DLN As Int64) As mmBindingList(Of ?)

Yes, you can use generics to solve this problem. You can declare a method in your interface that accepts a generic parameter, then implement that interface method in each business object. Then, you can specify the desire entity type when calling that method.

For example here is the method declaration in the interface:
using OakLeaf.MM.Main.Collections;
using OakLeaf.MM.Main.Business;

public interface IDataCap
{
	mmBindingList<EntityType> FetchByDLN<EntityType>(Int64 dln) where EntityType : mmBusinessEntity, new();
}
Here is the method implementation in the business objects (if your business objects share a common ancestor you can implement this method in the ancestor and it will be inherited):
public mmBindingList<EntityType> FetchByDLN<EntityType>(long dln) where EntityType : mmBusinessEntity, new()
{
	return this.GetEntityList<EntityType>("MyCommand");
}
And here is how you call the method:
mmBindingList<MyEntityType> entityList = MyBizObj.FetchByDLN<MyEntityType>(1234);
And here is the code in VB .NET:
Public Interface IDataCap

    Function FetchByDLN(Of EntityType As {New, mmBusinessEntity})(ByVal dln As Int64) As mmBindingList(Of EntityType)

End Interface

Public Function FetchByDLN(Of EntityType As {New, mmBusinessEntity})(ByVal dln As Long) As mmBindingList(Of EntityType) Implements IDataCap.FetchByDLN

        Return Me.GetEntityList(Of EntityType)("MyCommand")

End Function

Dim entityList As mmBindingList(Of MyEntityType) = Me.FetchByDLN(Of MyEntityType)(1234)
Best Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform