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

Binder fix #226

Merged
merged 3 commits into from
Feb 6, 2024
Merged

Binder fix #226

merged 3 commits into from
Feb 6, 2024

Conversation

MarkPflug
Copy link
Owner

No description provided.

@ChairmanMawh
Copy link

ChairmanMawh commented Nov 17, 2023

This would be my preference for lines ~456+ of CompiledDataBinder.cs:

		string[]? unboundProperties = null;
		string[]? unboundColumns = null;

		string? errorMessage = null;

		if (boundPropertyCount == 0)
		{
			errorMessage = $"None of the properties on the target type ({recordType.Name}) have been successfully bound to a column on the data source. Check the schema/code definition and refer to the " +
				".UnboundProperties / .UnboundColumns properties of this exception for details of what can be bound";

		}
		else if (opts.BindingMode.HasFlag(DataBindingMode.AllProperties) && properties.Any())
		{
			unboundProperties = properties.Select(p => p.Value.Name).ToArray();
			errorMessage = $"The DataBindingMode '{opts.BindingMode}' requires that all properties of the target type ({recordType.Name}) are bound to a column, but currently {unboundProperties.Length} " +
				$"properties are not successfully bound. Check the .UnboundProperties of this exception and adjust the code/schema, or adjust the binding mode by passing a " +
				$"DataBinderOptions object when calling GetRecords()";

		}else if (opts.BindingMode.HasFlag(DataBindingMode.AllColumns) && physicalColumns.Any())
		{
			unboundColumns = physicalColumns.Select(p => p.ColumnName).ToArray();
			errorMessage = $"The DataBindingMode '{opts.BindingMode}' requires that all columns of the data source are bound to a property on the target type ({recordType.Name}), but currently " +
				$"{unboundColumns.Length} columns are not successfully bound. Check the .UnboundColumns of this exception and adjust the code/schema, or adjust the binding mode " +
				$"by passing a DataBinderOptions instance when calling GetRecords()";

		}		
		else if (requiredProperties.Any())
		{
			unboundProperties = requiredProperties.ToArray();
			unboundColumns = physicalColumns.Select(p => p.ColumnName).ToArray();
			errorMessage = $"{unboundProperties.Length} properties on the target type ({recordType.Name}) are marked as required, but they are not bound to a column on the data source. " +
				$"Check the .UnboundProperties of this exception and adjust the code/schema so that they bind successfully, or remove their [DataMember(IsRequired=true)] requirement";

		}

		if (errorMessage != null)
		{
			throw new UnboundMemberException(errorMessage, unboundProperties ?? Array.Empty<string>(), unboundColumns ?? Array.Empty<string>());
		}

@MarkPflug MarkPflug merged commit 2b304aa into main Feb 6, 2024
1 check passed
@MarkPflug MarkPflug deleted the binder_fix branch February 6, 2024 15:47
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 this pull request may close these issues.

None yet

2 participants