[U] public void CanGetRoutingFromDocument() { /** By default NEST will try to find a property called `Routing` on the class using reflection * and create a cached delegate based on the property getter */ var dto = new MyDTO { Routing = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect(null).WhenInferringRoutingOn(dto); /** * Using connection settings, you can specify a property that NEST should use to infer Routing for the document. * Here we instruct NEST to infer the Routing for `MyDTO` based on its `Name` property */ WithConnectionSettings(x => x .DefaultMappingFor <MyDTO>(m => m .RoutingProperty(p => p.Name) ) ).Expect("x").WhenInferringRoutingOn(dto); /** IMPORTANT: Inference rules are cached __per__ `ConnectionSettings` instance. * * Because the cache is per `ConnectionSettings` instance, we can create another `ConnectionSettings` instance * with different inference rules */ WithConnectionSettings(x => x .DefaultMappingFor <MyDTO>(m => m .RoutingProperty(p => p.OtherName) ) ).Expect("y").WhenInferringRoutingOn(dto); }
[U] public void CanGetIdFromDocument() { /** By default NEST will try to find a property called `Id` on the class using reflection * and create a cached fast func delegate based on the properties getter */ var dto = new MyDTO { Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("d70bd3cf-4e38-46f3-91ca-fcbef29b148e").WhenInferringIdOn(dto); /** Using the connection settings you can specify a different property that NEST should use to infer the document Id. * Here we instruct NEST to infer the Id for `MyDTO` based on its `Name` property */ WithConnectionSettings(x => x .InferMappingFor<MyDTO>(m => m .IdProperty(p => p.Name) ) ).Expect("x").WhenInferringIdOn(dto); /** IMPORTANT: Inference rules are cached __per__ `ConnectionSettings` instance. * * Because the cache is per `ConnectionSettings` instance, we can create another `ConnectionSettings` instance * with different inference rules */ WithConnectionSettings(x => x .InferMappingFor<MyDTO>(m => m .IdProperty(p => p.OtherName) ) ).Expect("y").WhenInferringIdOn(dto); }
[U] public void CanGetIdFromDocument() { /** By default NEST will try to find a property called `Id` on the class using reflection * and create a cached fast func delegate based on the properties getter*/ var dto = new MyDTO { Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("d70bd3cf-4e38-46f3-91ca-fcbef29b148e").WhenInferringIdOn(dto); /** Using the connection settings you can specify a different property NEST should look for ids. * Here we instruct NEST to infer the Id for MyDTO based on its Name property */ WithConnectionSettings(x => x .InferMappingFor <MyDTO>(m => m .IdProperty(p => p.Name) ) ).Expect("x").WhenInferringIdOn(dto); /** Even though we have a cache at play the cache is per connection settings, so we can create a different config */ WithConnectionSettings(x => x .InferMappingFor <MyDTO>(m => m .IdProperty(p => p.OtherName) ) ).Expect("y").WhenInferringIdOn(dto); }
[U] public void CanGetIdFromDocument() { /** By default NEST will try to find a property called `Id` on the class using reflection * and create a cached fast func delegate based on the properties getter */ var dto = new MyDTO { Id = new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("d70bd3cf-4e38-46f3-91ca-fcbef29b148e").WhenInferringIdOn(dto); /** Using the connection settings you can specify a different property that NEST should use to infer the document Id. * Here we instruct NEST to infer the Id for `MyDTO` based on its `Name` property */ WithConnectionSettings(x => x .InferMappingFor <MyDTO>(m => m .IdProperty(p => p.Name) ) ).Expect("x").WhenInferringIdOn(dto); /** IMPORTANT: Inference rules are cached __per__ `ConnectionSettings` instance. * * Because the cache is per `ConnectionSettings` instance, we can create another `ConnectionSettings` instance * with different inference rules */ WithConnectionSettings(x => x .InferMappingFor <MyDTO>(m => m .IdProperty(p => p.OtherName) ) ).Expect("y").WhenInferringIdOn(dto); }
public async Task <IActionResult> Add([FromBody] MyDTO newDTO) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } return(Ok()); }
public static string GetName(this MyDTO myDto) { if (string.IsNullOrEmpty(myDto.Name)) { return(Name); } return(myDto.Name); }
public MyDTO Test() { // 1. Get content from umbraco var content = Umbraco.TypedContent(1122); // 2. Create instance of your own DTO var myDTO = new MyDTO(); // 3. Pupulate your DTO myDTO.SomeProperty = content.SomeProperty; // 4. return it return(myDTO); }
[U] public void CanGetIdFromDocument() { /** By default NEST will try to find a property called `Id` on the class using reflection * and create a cached fast func based on the properties getter*/ var dto = new MyDTO { Id =new Guid("D70BD3CF-4E38-46F3-91CA-FCBEF29B148E"), Name = "x", OtherName = "y" }; Expect("d70bd3cf-4e38-46f3-91ca-fcbef29b148e").WhenInferringIdOn(dto); /** Using the connection settings you can specify a different property NEST should look for ids. * Here we instruct NEST to infer the Id for MyDTO based on its Name property */ WithConnectionSettings(x => x .InferMappingFor<MyDTO>(m => m .IdProperty(p => p.Name) ) ).Expect("x").WhenInferringIdOn(dto); /** Eventhough we have a cache at play the cache its per connection settings, so we can create a different config */ WithConnectionSettings(x => x .InferMappingFor<MyDTO>(m => m .IdProperty(p => p.OtherName) ) ).Expect("y").WhenInferringIdOn(dto); }
public MyDTO(MyDTO dto) { this.Id = Id; this.Info = JsonConvert.DeserializeObject <T>(dto.Info); }