This is a migrated thread and some comments may be shown as answers.

Returning IList from a public static method

3 Answers 289 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
richardFlow
Top achievements
Rank 1
richardFlow asked on 18 Feb 2009, 10:47 AM
Hi,

I've a public static method on my SalesPrice class that returns sales prices based on certain parameters.

 

public static IList<SalesPrice> GetSalesPricesbyPK(int? SkuUid, SalesTypeEnum? SalesType, string SalesCode, DateTime? StartingDate)

{

 

IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();

scope.Transaction.Begin();

string  

 

oql = "SELECT * FROM SalesPriceExtent AS sp";
...
... conditional where clause building
...
IQuery query = scope.GetOqlQuery(oql);

 

 

 

 

IQueryResult result = query.Execute();

return ????????;

I have 3 questions.

1. Should i be passing in my scope object from the calling webpage to the method? Is this the best practice?
2. How do i convert from an IQueryResult to an IList<> ?
3. When is the best time to dispose the IQueryResult?  If I dispose it how do i return it?

Thanks!

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 18 Feb 2009, 02:19 PM
Hello Web Belief Ltd,

You can make your method return IList instead of IList<SalesPrice>. This way you can return IQueryResult, because IQueryResult implements IList, but its not generic collection.

Regarding your first and third question its best to take a look at our best practices knowledge base article

Regards,
PetarP
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
richardFlow
Top achievements
Rank 1
answered on 18 Feb 2009, 07:38 PM
When i try to change the return type to IList only I get the following error on compilation:

"Using the generic type 'System.Collections.Generic.IList<T>' requires '1' type arguments"

I can't get around this so far.

Regards,

Richard.
0
Accepted
PetarP
Telerik team
answered on 19 Feb 2009, 08:44 AM
Hi Web Belief Ltd,
you need to add
using System.Collections; 
so that the IList type is resolved correctly.

All the best,
PetarP
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
richardFlow
Top achievements
Rank 1
Answers by
PetarP
Telerik team
richardFlow
Top achievements
Rank 1
Share this question
or