忽略模型属性上的属性 [英] Ignore property on model property

查看:107
本文介绍了忽略模型属性上的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用dapper/dapper扩展名/dapper rainbow或任何

How can I ignore a property on my model using dapper/dapper extensions/dapper rainbow or any

?

推荐答案

Dapper的创建者Sam Saffron已针对另一位SO用户的问题解决了这一要求

Dapper creator Sam Saffron has addressed this requirement in response to another SO user's questions here. Check it out.

此外,如果您要使用Sam在回答中提到的 Dapper扩展库 ,您可以从Github或通过Nuget获取它.

Also, if you want to use the Dapper Extensions library that Sam has mentioned in his answer, you can get it from Github or via Nuget.

下面是一个示例,该示例忽略了库的测试项目.

Here's an example of ignoring properties from the Library's Test Project.

using System;
using System.Collections.Generic;
using DapperExtensions.Mapper;

namespace DapperExtensions.Test.Data
{
    public class Person
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public DateTime DateCreated { get; set; }
        public bool Active { get; set; }
        public IEnumerable<Phone> Phones { get; private set; }
    }

    public class Phone
    {
        public int Id { get; set; }
        public string Value { get; set; }
    }

    public class PersonMapper : ClassMapper<Person>
    {
        public PersonMapper()
        {
            Table("Person");
            Map(m => m.Phones).Ignore();
            AutoMap();
        }
    }
}

这篇关于忽略模型属性上的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆