The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Transparent cross-platform support for MS SQL and Oracle databases

Last post 02-20-2008, 4:56 AM by Mike.Griffin. 4 replies.
Sort Posts: Previous Next
  •  02-19-2008, 5:20 AM 8130

    Transparent cross-platform support for MS SQL and Oracle databases

    Hello,

    I have MQ SQL database, application working with it via EntitySpaces layer, set of es classes egenrated against this MS SQL database.

    Now I have to use this application against Oracle database (db schema is fairly same except GUID primary keys which are replaced by strings in Oracle database).

    The very first question: will these classes (i.e. es classes generated against MS SQL database) work transparently against Oracle database if we just replace provider settings in app.config settings? I'd like to have same code base (there is much added/customized in Custom partial classes for some bussiness logics) or should I generate es classes against Oracle db and have separate branches?

  •  02-19-2008, 6:20 AM 8131 in reply to 8130

    Re: Transparent cross-platform support for MS SQL and Oracle databases

    Just changing the connection would not be sufficient. Multi-Provider mode requires that you run the MetadataMap template against one of the databases. The problem, as noted in this FAQ, is that the schema must match. Having Guid PKs in your SQL Server database makes it nearly impossible to use Multi-Provider mode against Oracle. Your best bet is separate branches.
    David Neal Parsons
    www.entityspaces.net
  •  02-19-2008, 6:30 AM 8132 in reply to 8130

    Re: Transparent cross-platform support for MS SQL and Oracle databases

    David and I posted at the same time almost ;) It's always better to know that you have to write a cross db application before you start so that you can choose columns that match on all db systems, but I may have found a way for you. Unfortunately, GUID is one of the very few that doesn't port well (Amazing isn't it, you'd think by now these other systems would have it, it's to valuable not to have).

    Here is a post on our mutli-provider mode ==> POST

    Our Database Independent feature is pretty good and can degrade gracefully on columns that aren't exact matches, i.e. an 'int' can be used for a 'bit' and so on. You could possibly pull this off however on Guids.

    Suppose you generate against SQL as your master and you have a string of the proper length to hold the guid in Oracle as your PK. You run our extra Metadata map class against Oracle, the property for those columns will have been defined by SQL and be a guid. You can easily test this out in a quick sample app by following the instructions in the linked post. I'd create a quick little test app and use a single table in SQL and Oracle to test this. Use SQL as your master so your properties are of type guid then overload the PK property in your entity's custom class like so:

    I think that has a real good chance of working for you. I can tell you that our entire NUnit suite uses our Database Independent features, we run the same physical binary against all our supported databases including full hierarchical tests. Supporting a single code base it worth it in most cases.

    I would be very interested to see how this works for you. 

    Code:
    namespace BusinessObjects
    {
    public partial class Customers : esCustomers
    {
    // Override our PK property
    public override Guid? CustomerID
    {
    get
    {
    if (this.Row == null)
    {
    this.AddNew();
    }

    object o = this.Row[CustomersMetadata.ColumnNames.CustomerID];
    if (o is string)
    {
    // It must have come from Oracle, convert it.
    return new Guid(o);
    }
    else
    {
    // It's already a guid.
    return (Guid?)o;
    }
    }
    set
    {
    base.CustomerID = value;
    }
    }
    }
    }


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  02-20-2008, 1:35 AM 8141 in reply to 8132

    Re: Transparent cross-platform support for MS SQL and Oracle databases

    David, Mike - thank you very much. I'll try to manage it this week using your tips and links and get back here to let you know how it works for me once I have any results.

    Mike.Griffin:

    It's always better to know that you have to write a cross db application before you start so that you can choose columns that match on all db systems,

    Sure it's true, but first I wasn't as familiar with Oracle as with MS SQL and the fact that Oracle didn't have GUIDs was a big surprise for me Tongue Tied I started with MS SQL and did expect various kind of problems with Oracle in future but not things like this one...

  •  02-20-2008, 4:56 AM 8142 in reply to 8141

    Re: Transparent cross-platform support for MS SQL and Oracle databases

    I agree, it boggles my mind that these systems haven't added a GUID type.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
View as RSS news feed in XML