About

SubSonic is a .net open source project developed by Rob Conery and a core team of developers including Eric Kemp, Scott Watermasysk, Jon Galloway, Phil Haack, and Gavin Joyce. The current stable release is version 2.0.3. Nightly builds are available in our SVN respository.

Tags

SubSonic: Added Wildcard Methods

With revision 482 I added in the ability to work with string values and "LIKE" queries a little more intuitively.

On a recent post, a commenter (liviu) left this comment:

"...Because Subsonic generated code i found it unexplainable why i cannot write something like:

Select<Product>().Where( Schema.Product.ProductName.StartsWith("a"))

or

Select<Product>().Where(Schema.Product.ProductType == "Cool Engine")."

The good news here is that in the second case it's a matter of me writing more complete samples. You can indeed do this query this way:

IList<Product> products=new Select().From<Product>()
   .Where(Product.ProductTypeColum).IsEqualTo("Cool Engine")
   .ExecuteTypedCollection<Product>();

However liviu is correct - you can't use "StartsWith" or "EndsWith" - until now. I just checked in changeset 481 which allows you to use StartsWith() and EndsWith() as well as ContainsString() - here's my Unit Tests:

 

        [Test]
        public void Select_Using_StartsWith_C_ShouldReturn_9_Records() {


            int records = new Select().From<Product>()
                .Where(Northwind.Product.ProductNameColumn).StartsWith("c")
                .GetRecordCount();
            Assert.AreEqual(9, records);
        }

        [Test]
        public void Select_Using_EndsWith_S_ShouldReturn_9_Records() {


            int records = new Select().From<Product>()
                .Where(Northwind.Product.ProductNameColumn)
                .EndsWith("s").GetRecordCount();
            Assert.AreEqual(9, records);
        }


        [Test]
        public void Select_Using_Contains_Ch_ShouldReturn_14_Records() {


            int records = new Select().From<Product>()
                .Where(Northwind.Product.ProductNameColumn)
                .ContainsString("ch").GetRecordCount();

            Assert.AreEqual(14, records);
        }

 

Many thanks to liviu for the suggestions!

Subscribe