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

Enhancement: Revisits the Immutable Classes Instantiation #753

Closed
mikependon opened this issue Jan 23, 2021 · 2 comments
Closed

Enhancement: Revisits the Immutable Classes Instantiation #753

mikependon opened this issue Jan 23, 2021 · 2 comments
Assignees
Labels
deployed Feature or bug is deployed at the current release enhancement New feature or request

Comments

@mikependon
Copy link
Owner

Describe the enhancement

As a referenced to this issue #748 and to some various reports via GitterChat, the existing code for the classes with extra ctros were affected when the users upgraded the library from the version below v1.11.x to >= v1.12x. This is because the support to the immutable classes has been supported on this version.

Though we clearly explained it here, but I think, it is good if we can further optimize how the immutable classes instantiation behaved.

It is better if we can support the below.

// C#/F# records (basic)
public class C
{
	public C(string n, int v)
	{
		N = n;
		V = v;
	}
	public string N { get; }
	public int V { get; }
}

// Combination
public class C
{
	public C(string n)
	{
		N = n;
	}
	public string N { get; }
	public int V { get; set; }
}

// With Extra (default???)
public class C
{
	public C(string n, double notMapped)
	{
		N = n;
		NotMapped = notMapped;
	}
	public string N { get; }
	public double NotMapped { get; }
}

// Multiple Ctor
public class C
{
	public C(){ }
	public C(string n)
	{
		N = n;
	}
	public string N { get; }
}

// Multiple Ctor / Fallback
public class C
{
	public C(){ }
	public C(double notMapped)
	{
		NotMapped = notMapped;
	}
	public string N { get; set; }
	public double NotMapped { get; }
}

FYI: @kbilsted

@mikependon mikependon added the enhancement New feature or request label Jan 23, 2021
@mikependon mikependon self-assigned this Jan 23, 2021
mikependon added a commit that referenced this issue Feb 6, 2021
mikependon added a commit that referenced this issue Feb 6, 2021
#753 #761 - Added a descriptive message for the unmatched ctor argume…
@mikependon
Copy link
Owner Author

As part of the enhancement in order for the user to be notified of the ctor arguments problem, we will throw an exception instead, rather than passing the default value.

The message below will be thrown

System.MissingMemberException: 'The following ctor arguments ('extra') for type 'RepoDb.IntegrationTests.ImmutableTest+ImmutableWithUnmatchedCtorArgumentsFromMultipleCtors' are not matching from any of the resultset fields returned by the data reader object.'

If the extra ctor argument is not a column of the resultset of data reader.

mikependon added a commit that referenced this issue Feb 6, 2021
mikependon added a commit that referenced this issue Feb 6, 2021
@mikependon
Copy link
Owner Author

To simplify the things for this library and to avoid the confusion to the users whether which ctor is being called, we will always utilize the ctor with most number of arguments. If there are misalignment between the model properties and the data reader resultset fields, a descriptive exception message will be thrown back to the user. See the sample message below.

The following ctor arguments ('Address') for type 'Person' are not matching from any of the resultset fields returned by the data reader object.

Through this descriptive exception message, the user might be able to pinpoint the problem easily. In the sample above, the argument Address from the ctor of the Person class/model is not being returned by the data reader object.

@mikependon mikependon added the deployed Feature or bug is deployed at the current release label Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed Feature or bug is deployed at the current release enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant