Single entity to dataset?

Posts   
 
    
Vikruolis
User
Posts: 9
Joined: 06-Nov-2008
# Posted on: 06-Nov-2008 08:23:37   

Hello,

I am prety new in LLBLGen some maybe it is newbe question. So, I have web application and web service. Web service encapsulates all business logic and DB is "hidden" behind it. Web application uses web service as data provider. Web knows nothing about DB and even generated entity classes. So comunication data types in most cases are primitives or datasets. I don't care about relations, database fields info, I need only pure data. For entity collections datasets are perfect. Example bellow is how I return collections: [WebMethod] public DataSet GetFoldersList() { ReportAccessItemCollection aList = new ReportAccessItemCollection(); aList.GetMulti(null); DataSet retVal = new DataSet(); aList.CreateHierarchicalProjection(retVal); return retVal; }

I face problem when I want to return single entity as DataSet: [WebMethod] public DataSet GetFoldersByKey(int p_nFolderKey) { ReportAccessItemEntity anAccess = new ReportAccessItemEntity(p_nFolderKey); ... DataSet retVal = new DataSet(); ... return retVal; }

So, I see 3 solutions here: 1. to make fake collection and call CreateHierarchicalProjection function 2. any single object loads proceed with collection GetMulti function with filter(ID = parameter_key) and again CreateHierarchicalProjection function 3. to create nested class in web service class which will be like structure for single object data return

Any other suggestions?

Thank you in advance. BR, Marius

Vikruolis
User
Posts: 9
Joined: 06-Nov-2008
# Posted on: 06-Nov-2008 09:51:07   

Problem solved as follows:

[WebMethod] public DataSet GetFoldersByKey(int p_nFolderKey) { ReportAccessItemEntity anAccess = new ReportAccessItemEntity(p_nFolderKey); PrefetchPath2 path = new PrefetchPath2(EntityType.ReportAccessItemEntity);

    DataSet retVal = GeneralUtils.ProduceEmptyDataSet(path, new ElementCreator());

    object[] val = new object[anAccess.Fields.Count];
    for (int i = 0; i < anAccess.Fields.Count; i++)
        val[i] = anAccess.Fields[i].CurrentValue;
    retVal.Tables[0].Rows.Add(val);

    return retVal;
}

Maybe it would be nice to have such functionality for Entity in future releases. BR, Marius

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Nov-2008 11:23:08   

You may use DTOs (to be generated for you). There some 3rd party DTO templates on the forums, please seach the forum for DTO.

Example: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=13256