Massive icon indicating copy to clipboard operation
Massive copied to clipboard

Add columns support to Single overload

Open mikebeaton opened this issue 8 years ago • 1 comments

The version of Single() at line 509 of Massive.Shared.cs with signature public virtual dynamic Single(string where, params object[] args) does not support a columns argument.

This would actually be very useful to have. I think so because I needed it in the project I'm working on, and added it for myself and used it a lot, and I think so because All() supports columns, and the other explicit version of Single() supports columns, and all the rather cryptic variants of Single() which are dynamically supported by TryInvokeMember support columns.

It's easy to add an optional columns param, with default value * to this method (which is what I did), and this would link against existing code, but I think from your contribution guidelines it should be added as another new method.

mikebeaton avatar Jan 29 '17 09:01 mikebeaton

This is definitely (or almost definitely, see last para below...) a breaking change. The obvious new method signature is public virtual dynamic Single(string where, string columns = "*", params object[] args) (to replace public virtual dynamic Single(string where, params object[] args)). But this will break existing code, causing, e.g., db.Single("BusinessEntityID=@0", 1234) to no longer compile.

It appears at first that something even worse would happen, namely that db.Single("CompanyName=@0", "Microsoft") would compile and run, but the intended string parameter would become newly misinterpreted as a columns specification. Actually this problem cannot happen, only because db.Single("CompanyName=@0", "Microsoft") cannot be in previous code as it would previously have refused to compile(!), due to ambiguity with the public virtual dynamic Single(object key, string columns = "*") method signature. (This call would however start to compile and behave incorrectly, given the new Single method signature... but you wouldn't ever add it, because IntelliSense would be telling you that you were putting args into a columns parameter!)

Despite all that, it would still actually be possible to support a columns plus args variant of Single without breaking any existing code, if it was supported dynamically (but only dynamically, c.f. #287) in TryInvokeMember - because dynamically supported methods are only invoked if no explicitly defined method can be used. That assumes that TryInvokeMember can itself be refactored to fully and correctly support args (cf #285 which attempts this, but does not succeed) - which in fact it can be in principle, but only if named args support is added...

mikebeaton avatar Feb 10 '17 15:02 mikebeaton