
Something that was born out of a project I’ve been working on is a simple repository for SalesLogix that supports all the way back to SalesLogix v6.2 up to the current 7.5.3, both LAN and Web as well as stand alone applications and utilities. I’ve named it Sublogix. Sublogix is a simple object model and repository for SalesLogix. Sublogix is not meant to replace the SalesLogix Repository that lives in SalesLogix Web. It’s purpose is to give you the ability to work with SalesLogix entity objects no matter what environment you’re in.
Recently, I had a SalesLogix LAN project I had to work on, which to be honest, I’ve not worked in SalesLogix LAN for quite some time. It was a miserable experience. In my opinion, any code that is riddled with SQL statements is bad code. The worst kind of code. Unfortunately, that kind of code is typical for what you see in LAN client development or even in addon utilities for SalesLogix. The problem all comes down to the SalesLogix OLEDB provider, some of it’s quirks, and the lack of something better to use. I’m a big fan of Subsonic and Sublogix is inspired by Subsonic’s SimpleRepository (I did not attempt to implement something as complete as Subsonic’s ActiveRecord, I just needed a simple repository that worked the way SalesLogix works with it’s custom ID scheme and so forth that would work via the SalesLogix Provider). To be honest, I didn’t intend to name Sublogix after Subsonic, but rather to have a name similar to Subtext, which is a blogging engine with a name that implies it is the engine beneath the text. That’s what I wanted in a name for Sublogix. It’s underneath the real work you do, doing it’s job, and you don’t even know it’s there.
Some scenarios that are a perfect place to use Sublogix:
- Custom stand alone applications or utilities for SalesLogix
- LAN client customizations by way of .NET Extensions
- Any app where you need to create, read, update, or delete SalesLogix data (and don’t have access to the SalesLogix entity model)
- A web application for an older version of SalesLogix
Let’s take a look at some code using Sublogix.
Updating an Account
// Open a the repository var repo = new Repository(Global.ConnectionString); // Locate an account and change the Type var account = repo.GetById<Account>("AA2EK0013096"); account.Type = newValue; // Save it account.Save(); |
Create a new Account
// Open the repository var repo = new Repository(Global.ConnectionString); // Create a new Account and set some values var account = repo.Create<Account>(); account.AccountName = "Test Account"; account.Type = "Test"; account.Mainphone = "6235551212"; // Save it account.Save(); |
Locating Contacts using an Expression
// We'll locate a list of contacts using an expression // and then create an opportunity under each one var repo = new Repository(Global.ConnectionString); var contactList = repo.Find<Contact>(x => x.Type == "Customer"); foreach (var contact in contactList) { var opp = repo.Create<Opportunity>(); opp.ContactId = contact.Id; opp.AccountId = contact.AccountId; opp.Description = "Customer Opportunity"; //... opp.Save(); } |
Locating Accounts with an Expression
// We'll locate a list of accounts using an expression // All accounts with account name starting with "Abb" var repo = new Repository(Global.ConnectionString); var accountList = repo.Find<Account>(x => x.AccountName.StartsWith("Abb")); foreach (var account in accountList) { //... } |
All of that code looks easy enough, right? No need to every write a SQL statement for SalesLogix applications again. 🙂 Sublogix works with your own custom tables as well. It comes with some handy T4 templates you just drop into your solution in Visual Studio and your model is instantly generated for you.
What’s in the Future for Sublogix?
Sublogix is already something I am using in a production application for a customer. But there is a lot more I plan on adding to it. Here’s a short list of what I plan on doing with Sublogix in the near future:
- Make it available for public use. This will happen soon.
- Build out the expression factory even more. The current expression factory in Sublogix today is pretty simple. There’s a lot more I’d like to do with it.
- Build in a Linq provider. I’d like Sublogix to fully support Linq to make it even easier to work with
- Best of all, Sublogix will (in the future) work with both local databases or with SData. You’ll be able to write code to work against a local database and then with only changing the line that instantiates the repository to have it work with SData.
Wait, what? Yes, I’d like to be able to use the exact same code to work with both a local SalesLogix database using the SalesLogix Provider as well as work with SData behind the scenes. That would be completely awesome.
So instead of doing this, to create a repository using an OLEDB connection string:
var repo = new Repository(Global.ConnectionString); |
You’d do this, to pass an SData URL:
var repo = new Repository(SDataUrl, UserName, Password); |
Other than that small change, the rest of the code would work as is. I’m pretty excited to get that built in. Anyway, that is where I would like to take it.
So what are your thoughts? I’d love to hear them. Stay tuned for Sublogix to be available for you to use as well.
Ryan, I figured it out. Typo. Sorry. Thanks for you time.