How to avoid errors in SubSonic 3 if the singular name of a column is the same as the table name?

StackOverflow https://stackoverflow.com/questions/8154047

  •  02-03-2021
  •  | 
  •  

Question

Sorry for the confusing title, I wasn't sure how to word it any differently...

Ok, here's the issue:

I have a table named "Products" and the primary key is "Product". Normally, this doesn't cause any issues. However, I'm switching to SubSonic 3 and it makes all the tables singular. Thus, when I rebuild the T4 Templates it throws an error as it renamed the column to "ProductX" but doesn't update the rest of the code. For example, this errors out:

public IQueryable<Product> Products
    {
        get
        {
              var repo=AM.Inventory.Library.SonicData.Product.GetRepo();
              return from items in repo.GetAll()
                   where items.Product == _Product
                   select items;
        }
    }

But, if I change it to:

public IQueryable<Product> Products
    {
        get
        {
              var repo=AM.Inventory.Library.SonicData.Product.GetRepo();
              return from items in repo.GetAll()
                   where items.ProductX == _Product
                   select items;
        }
    }

The code will build just fine. If I had to do this once or twice, that's fine... but whenever I rebuild the T4 files I'd have to update the files manually.

Is there any way to avoid this?

Thanks, Andrew

Was it helpful?

Solution

Modify your T4 templates. That's what they're there for.

Look for MakeSingular(), MakePlural(), Cleanup() in the ttincludes, and the code that adds the "X" is in ActiveRecord.tt. Hack 'em!!!

Actually, it sounds like a bug in the naming code, so this might be the time for making a contribution by squashing the bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top