小编And*_*bæk的帖子

将Expression <Func>映射到另一个Expression <Func>中的DTO类

我正在使用Entity Framework Code First并尝试从我的实体类映射到我的DTO类.但我很难搞清楚如何编写Selector.

在这个小例子中,我创建了一个Person类和一个Address类.

在DTO类中,我创建了一个Selector,它从我的Entity映射到我的DTO,但是不能在PersonDto.Selector中使用AddressDto.Selector吗?

public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public Address Address { get; set; }
    }

    public class Address
    {
        public int Id { get; set; }
        public string Street { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试将其映射到DTO类.

    public class PersonDto
        {
            public static Expression<Func<Person, PersonDto>> Selector = 
            entity => new PersonDto
                {
                     Id = entity.Id,
                     Name = entity.Name,
                     Address = ??? AddressDTO.Selector
                };

            public int …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework dto

4
推荐指数
1
解决办法
2100
查看次数

Woocommerce显示默认变化价格

我正在使用Woocommerce和产品变体,所有变体都定义了默认变体。我想知道如何找到默认变体并显示其价格。

这是我到目前为止获得的代码,但是它显示了最低的变动价格,而我正在寻找默认的变动产品价格。

// Use WC 2.0 variable price format, now include sale price strikeout
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
function wc_wc20_variation_price_format( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'HERE YOUR LANGUAGE: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( …
Run Code Online (Sandbox Code Playgroud)

wordpress variations woocommerce

3
推荐指数
2
解决办法
7608
查看次数

使用ASP.NET MVC路由等路由解析对象

在ASP.NET MVC中,可以定义这样的路由:

routes.MapRoute("myroute",
    "myroute/{country}/{name}-{type}",
    new { controller = "MyController", action = "Get" });
Run Code Online (Sandbox Code Playgroud)

这会将它直接解析为一个对象:

public class MyController : Controller
{
   public HttpResponseMessage Get([FromRoute] MyViewModel model)
   {
      //TODO do stuff with model.
   }
}
Run Code Online (Sandbox Code Playgroud)

这是我的视图模型:

public class MyViewModel
{
    public string Name { get; set; }
    public string Type{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,我可以在一个简单的控制台应用程序中进行相同的解析吗?

class Program
{
    static void Main(string[] args)
    {
        string route = "myroute/{country}/{name}-{type}";

        string input = "myroute/Denmark/MyName-MyType";

        //TODO Parse input to MyViewModel with route
        MyViewModel result;
    }
} …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-routing .net-core asp.net-core

1
推荐指数
1
解决办法
404
查看次数