[U] public void CanGetIdFromAttribute() { /** Now when we infer the id we expect it to be the value of the `Name` property without doing any configuration on the `ConnectionSettings` */ var dto = new MyOtherDTO { Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("x").WhenInferringIdOn(dto); /** * ==== Using Mapping inference on ConnectionSettings * * This attribute *is* cached statically/globally, however an inference rule on the `ConnectionSettings` for the type will * still win over the attribute. Here we demonstrate this by creating a different `ConnectionSettings` instance * that will infer the document id from the property `OtherName`: */ WithConnectionSettings(x => x .DefaultMappingFor <MyOtherDTO>(m => m .IdProperty(p => p.OtherName) ) ).Expect("y").WhenInferringIdOn(dto); }
/** ==== Disabling Id inference */ [U] public void DisablingIdInference() { // hide var dto = new MyOtherDTO { Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; /** * You can configure the client to disable Id inference on a CLR type basis */ WithConnectionSettings(x => x .DefaultMappingFor <MyOtherDTO>(m => m .DisableIdInference() ) ).Expect(null).WhenInferringIdOn(dto); /** * or globally for all types */ WithConnectionSettings(x => x.DefaultDisableIdInference()) .Expect(null).WhenInferringIdOn(dto); /** * Once disabled globally, Id inference cannot be enabled per type */ WithConnectionSettings(x => x .DefaultDisableIdInference() .DefaultMappingFor <MyOtherDTO>(m => m .DisableIdInference(disable: false) ) ).Expect(null).WhenInferringIdOn(dto); }
[U] public void CanGetIdFromAttribute() { /** Now when we infer the id we expect it to be the Name property without doing any configuration on the ConnectionSettings */ var dto = new MyOtherDTO { Id =new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("x").WhenInferringIdOn(dto); /** This attribute IS cached statically/globally, however connectionsettings with a config for the type will * still win over this static configuration*/ /** Eventhough we have a cache at play the cache its per connection settings, so we can create a different config */ WithConnectionSettings(x => x .InferMappingFor<MyOtherDTO>(m => m .IdProperty(p => p.OtherName) ) ).Expect("y").WhenInferringIdOn(dto); }
[U] public void CanGetIdFromAttribute() { /** Now when we infer the id we expect it to be the Name property without doing any configuration on the ConnectionSettings */ var dto = new MyOtherDTO { Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("x").WhenInferringIdOn(dto); /** This attribute IS cached statically/globally, however connectionsettings with a config for the type will * still win over this static configuration*/ /** Eventhough we have a cache at play the cache its per connection settings, so we can create a different config */ WithConnectionSettings(x => x .InferMappingFor <MyOtherDTO>(m => m .IdProperty(p => p.OtherName) ) ).Expect("y").WhenInferringIdOn(dto); }
[U] public void CanGetRoutingFromJoinField() { /** here we link this instance of `MyOtherDTO` with its parent id `"8080"` */ var dto = new MyOtherDTO { SomeJoinField = JoinField.Link <MyOtherDTO>("8080"), Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("8080").WhenInferringRoutingOn(dto); /** * Here we link this instance as the root (parent) of the relation. NEST infers that the default routing for this instance * should be the Id of the document itself. */ dto = new MyOtherDTO { SomeJoinField = JoinField.Root <MyOtherDTO>(), Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("d70bd3cf-4e38-46f3-91ca-fcbef29b148e").WhenInferringRoutingOn(dto); /** * ==== Precedence of ConnectionSettings * * The routing property configured on `ConnectionSettings` always takes precedence. * */ WithConnectionSettings(x => x .DefaultMappingFor <MyOtherDTO>(m => m .RoutingProperty(p => p.OtherName) ) ).Expect("y").WhenInferringRoutingOn(dto); }
[U] public void CanGetIdFromAttribute() { /** Now when we infer the id we expect it to be the value of the `Name` property without doing any configuration on the `ConnectionSettings` */ var dto = new MyOtherDTO { Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("x").WhenInferringIdOn(dto); /** === Using Mapping inference on ConnectionSettings * * This attribute *is* cached statically/globally, however an inference rule on the `ConnectionSettings` for the type will * still win over the attribute. Here we demonstrate this by creating a different `ConnectionSettings` instance * that will infer the document id from the property `OtherName`: */ WithConnectionSettings(x => x .InferMappingFor<MyOtherDTO>(m => m .IdProperty(p => p.OtherName) ) ).Expect("y").WhenInferringIdOn(dto); }