我正在使用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) 我正在使用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) 在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# ×2
.net ×1
.net-core ×1
asp.net-core ×1
asp.net-mvc ×1
dto ×1
variations ×1
woocommerce ×1
wordpress ×1