Skip to content

Conversation

@Mpdreamz
Copy link
Member

@Mpdreamz Mpdreamz commented Nov 4, 2016

... to map inside the fluent properties descriptor

.Properties(ps => ps
 	.Scalar(p => p.Int, m => m)
 	.Scalar(p => p.IntNullable, m => m)
 	.Scalar(p => p.Float, m => m)
 	.Scalar(p => p.FloatNullable, m => m)
 	.Scalar(p => p.Char, m => m)
 	.Scalar(p => p.CharNullable, m => m)
 	.Scalar(p => p.Guid, m => m)
///snip 	
	.Scalar(p => p.String, m => m)
 );

Copy link
Contributor

@gmarz gmarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't overload Number() and Date() rather than introducing Scalar()?

…ier to map inside the fluent properties descriptor
@Mpdreamz Mpdreamz force-pushed the fix/easier-scalar-mappings branch from 37c70d7 to f2b6400 Compare November 4, 2016 19:37
@Mpdreamz
Copy link
Member Author

Mpdreamz commented Nov 4, 2016

@gmarz I quite like the separate Scalar route with overloads .Number(n=> would be amiguous until either its closed by ) or you type ,.

The other reason i quite like Scalar is that in fluent mapping it doesn't flow too well you have to know what type you are going to target before specifying the name.

With .Scalar( you can simply map 90% of the properties in a much more exploratory friendly way.

@russcam
Copy link
Contributor

russcam commented Nov 10, 2016

Check CLS Compliance for this

SetProperty(selector?.InvokeOrDefault(new KeywordPropertyDescriptor<T>().Name(field)));

public PropertiesDescriptor<T> Scalar(Expression<Func<T, string>> field, Func<TextPropertyDescriptor<T>, ITextProperty> selector) =>
SetProperty(selector?.InvokeOrDefault(new TextPropertyDescriptor<T>().Name(field)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do the same thing as string inference on automapping i.e. add a keyword multi_field

@russcam
Copy link
Contributor

russcam commented Nov 10, 2016

Add IEnumerable overloads

@gmarz
Copy link
Contributor

gmarz commented Nov 11, 2016

@forloop I added IEnumerable overloads with my last commit. Mind giving this a final review?

Copy link
Contributor

@russcam russcam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment, otherwise LGTM


#pragma warning disable CS3001 // Argument type is not CLS-compliant
public IProperty Scalar(Expression<Func<T, int>> field, Func<NumberPropertyDescriptor<T>, INumberProperty> selector) =>
selector?.InvokeOrDefault(new NumberPropertyDescriptor<T>().Name(field).Type(NumberType.Integer));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these should be

selector.InvokeOrDefault(...)

if selector is null, we want to return the default, but the null conditional on the .InvokeOrDefault() will return null if selector is null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep! good catch will fix these now.

@Mpdreamz Mpdreamz dismissed russcam’s stale review November 18, 2016 11:51

Handled remaining comment

@Mpdreamz Mpdreamz merged commit 345eb8d into master Nov 18, 2016
Mpdreamz added a commit that referenced this pull request Nov 18, 2016
…ier (#2372)

* fix #2368 by fixing the underlying problem that scalars should be easier to map inside the fluent properties descriptor

* remove compiler warnings

* Add IEnumerable overloads

* selector?.InvokeOrDefault => selector.InvokeOrDefault
@Mpdreamz
Copy link
Member Author

merged to master and 5.x

@Mpdreamz Mpdreamz deleted the fix/easier-scalar-mappings branch November 30, 2016 16:58
awelburn pushed a commit to Artesian/elasticsearch-net that referenced this pull request Nov 6, 2017
… be easier (elastic#2372)

* fix elastic#2368 by fixing the underlying problem that scalars should be easier to map inside the fluent properties descriptor

* remove compiler warnings

* Add IEnumerable overloads

* selector?.InvokeOrDefault => selector.InvokeOrDefault
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.

4 participants