PowerShell Remoting Project Home

Sunday, January 01, 2006

Working with SQL server in monad using pre-compiled .NET Class Library (2)

Now we can do something fun.

1. Add following code to our PlasmidView.DLL


using System.Collections;
namespace PlasmidView
{
     public class SQLProvider
     {

// return ArrayList of “PlasmidCore” objects of all plasmid information
public static ArrayList Plasmid_All ()
{...}

// return a PlasmidCore object
public static PlasmidCore PlasmidCore_ByPlasmidID (int plasmidid)
{...}

// return User objects
public static User User_ByUserID (int userid)
{...}

// return Plasmid Type (String)
public static string PlasmidType_ByPlasmidTypeID (int plasmidTypeID)
{...}

public class PlasmidCore
{... }

public class User
{... }
}

I omit most of C# code here

2. Try to get all plasmid informtion

[void][System.Reflection.Assembly]::LoadFile("D:\MSH\PlasmidView.dll")
[PlasmidView.SQLProvider]::Plasmid_All()

PlasmidID       : 1
BoxID           : A
BoxPosition     : 1
PlasmidName     : pCMV4 Hygro
DateCreated     : 10/30/2005 8:58:24 PM
UserID          : 1
UserCreated     : me
PlasmidType     : Backbone Vector
PlasmidTypeID   : 1
ParentPlasmidID : 0
ParentPlasmid   : None

PlasmidID       : 2
BoxID           : A
BoxPosition     : 2
PlasmidName     : pCMV4 Neo
DateCreated     : 10/30/2005 9:07:16 PM
UserID          : 1
UserCreated     : me
PlasmidType     : Backbone Vector
PlasmidTypeID   : 1
ParentPlasmidID : 0
ParentPlasmid   : None


3. Try to search plasmid with “hygro” in their names:

[PlasmidView.SQLProvider]::Plasmid_All()  where-object {$_.PlasmidName -like “*hygro*”} foreach-object {“============”; “ID:”+ $_.PlasmidID; “Name:” + $_.PlasmidName}

============
ID:1
Name:pCMV4 Hygro
============
ID:20
Name:TAg Hygro


Conclusion:
1. We can easily return a group of objects to monad using ArrayList. Unlike strong typed language (for example, C#) monad detects the base object of each Item in ArrayList. You do NOT have to cast each ArrayList Item to its original base object (PlasmidView.PlasmidCore) when quoting them in a pipline.

2. When database is small, using where-object cmdlet to do search is a good idea. Actually I even forgot I had a Plasmid_Search( ) method in my original C# code. But when database grew bigger, better use a Search function to return limited number of objects only from search results.

Tags:    


Comments:

Post a Comment





<< Home