Using the same Code for Pervasive and SQL

To use the same code for Pervasive and SQL, simply add an if statement to distinguish the different behaviors.

if (ENV.Data.DataProvider.BtrieveMigration.UseBtrieve)
{
    ///code that is relevant for Btrieve
}
else
{
    /// code that is relevant for SQL
} 

You can use it for the Relation type, based using the inline if syntax condition?thenValue:elseValue

 Relations.Add(Orders, 
    ENV.Data.DataProvider.BtrieveMigration.UseBtrieve ? RelationType.Find : RelationType.OuterJoin, 
    Orders.OrderID.IsEqualTo(Order_Details.OrderID), Orders.SortByPK_Orders); 

You can use a helper class

public class SQLHelper
{
     public static RelationType OuterJoin() => 
         ENV.Data.DataProvider.BtrieveMigration.UseBtrieve ? RelationType.Find : RelationType.OuterJoin;
} 

And then in the code just call it

 Relations.Add(Orders, 
-   ENV.Data.DataProvider.BtrieveMigration.UseBtrieve ? RelationType.Find : RelationType.OuterJoin, 
    SQLHelper.OuterJoin(),
    Orders.OrderID.IsEqualTo(Order_Details.OrderID), Orders.SortByPK_Orders); 

Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com