相关疑难解决方法(0)

EF Code First阻止使用Fluent API进行属性映射

我有一个类Product和一个复杂的类型AddressDetails

public class Product
{
    public Guid Id { get; set; }

    public AddressDetails AddressDetails { get; set; }
}

public class AddressDetails
{
    public string City { get; set; }
    public string Country { get; set; }
    // other properties
}
Run Code Online (Sandbox Code Playgroud)

是否可以防止从类AddressDetails内部映射"Country"属性Product?(因为我在Product课堂上永远不需要它)

像这样的东西

Property(p => p.AddressDetails.Country).Ignore();
Run Code Online (Sandbox Code Playgroud)

c# entity-framework fluent-interface ef-code-first

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

如何将OData查询与DTO映射到另一个实体?

我的问题与此问题非常类似:如何将针对DTO的OData查询映射到EF实体? 我有一个简单的设置来测试ASP.NET Web API OData V4 $过滤器功能.我想做的是"别名"ProductDTO的一些属性以匹配Product实体的属性.用户将使用以下请求调用ProductsController:

GET产品?$ filter = DisplayName eq'test'

产品类:

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Level { get; set; }
    public Product()
    { }
}
Run Code Online (Sandbox Code Playgroud)

ProductDTO类:

public class ProductDTO
{
    public int Id { get; set; }
    public string DisplayName { get; set; }
    public int DisplayLevel { get; set; }
    public ProductDTO(Product product)
    {
        this.DisplayName = product.Name;
        this.DisplayLevel = product.Level; …
Run Code Online (Sandbox Code Playgroud)

c# odata asp.net-web-api

12
推荐指数
3
解决办法
1万
查看次数