Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Members not populated or saved when fieldName == tableName [fix code inside] #276

Closed
ghost opened this issue Dec 23, 2011 · 0 comments · May be fixed by #277
Closed

Members not populated or saved when fieldName == tableName [fix code inside] #276

ghost opened this issue Dec 23, 2011 · 0 comments · May be fixed by #277

Comments

@ghost
Copy link

ghost commented Dec 23, 2011

I ran into an issue where a column in my database was the same name as the table itself. Subsonic correctly generated a field for it (with 'X' appended) but it wouldn't save to the datastore, and it wouldn't be populated when I fetched data from the store.

I hacked a fix in, but it's almost Christmas and I don't want to go through the official patching whatnot, so here it is (both fixes in Subsonic.Core):

in Load in Database.cs (beneath line 159), add an additional check to find a property which, without the appended X, matches the property we're trying to assign to:

//if we didn't find the property, maybe we'll find it without the last character, e.g. 'X'
if (currentProp == null)
{
currentProp = cachedProps.SingleOrDefault(x => x.Name.Substring(0, x.Name.Length - 1).Equals(pName, StringComparison.InvariantCultureIgnoreCase));
}

And, in DatabaseTable.cs around line 142, the "GetColumnByPropertyName" method, I added a similar check to have the right column be found:

if (this.Name.Equals(PropertyName.Substring(0, PropertyName.Length - 1)) &&
PropertyName.EndsWith("X") &&
this.Columns.Any(x => x.Name == PropertyName.Substring(0, PropertyName.Length - 1)))
{PropertyName = PropertyName.Substring(0, PropertyName.Length - 1); }

Not sure this is up to snuff, but hey - it works and I get to go home. Cheers!

@ghost ghost closed this as completed Dec 27, 2011
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

0 participants