コード例 #1
0
        [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);
        }
コード例 #2
0
		[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);
		}
コード例 #3
0
ファイル: IdsInference.doc.cs プロジェクト: lukapor/NEST
        [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);
        }
コード例 #4
0
        [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);
        }
コード例 #5
0
 public async Task <IActionResult> Add([FromBody] MyDTO newDTO)
 {
     if (!this.ModelState.IsValid)
     {
         return(this.BadRequest());
     }
     return(Ok());
 }
コード例 #6
0
 public static string GetName(this MyDTO myDto)
 {
     if (string.IsNullOrEmpty(myDto.Name))
     {
         return(Name);
     }
     return(myDto.Name);
 }
コード例 #7
0
    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);
    }
コード例 #8
0
		[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);
		}
コード例 #9
0
 public MyDTO(MyDTO dto)
 {
     this.Id   = Id;
     this.Info = JsonConvert.DeserializeObject <T>(dto.Info);
 }