忽略AutoMapper中的内部列表属性的映射--EF6,C#

时间:2018-03-25 09:33:00

标签: c# .net entity-framework entity-framework-6 automapper

我有像这样的DTO的集合属性

"str01"

申请人模型

str1

我想将 public ICollection<Applicant> Applicants{get;set;} DTO映射到实体,因为我想要使用ApplicantSkillsVM但忽略public class Applicant { public int Id{get;set;} public string name{get;set;} public ICollection<ApplicantSkillsVM> ApplicantSkills { get; set; } } public class ApplicantSkillsVM { public int Id {get;set;} public Skill skill{get;set;} } 内的List<iApplicant>

我有一个列表为skill的模型,其中包含另一个列表ApplicantSkillsVM,而ApplicantSkillsVM的属性为List<Applicant>。我想在映射时忽略这个(List<ApplicantSkillsVM>)。这很简单。

如何在最新的带有EF6的AutoMapper版本中执行此操作?

2 个答案:

答案 0 :(得分:1)

这是一个正在运行的样本:

List<model> weather = new ArrayList<model>();

Query dbQuery = FirebaseDatabase.getInstance().getReference().child("NeuralNetwork");

    dbQuery.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            //Model
            model m = dataSnapshot.getValue(model.class);

            int prev = m.getPrevious();
            int hu = m.getHumidity();
            int tem = m.getTemperature();
            int wi = m.getWind();
            int nw = m.getNewValue();
            Toast.makeText(MainActivity.this, "value of temp" + temp, Toast.LENGTH_SHORT).show();


            weather.add(new model(prev, tem, hu, wi, nw));

        }

答案 1 :(得分:-1)

最初,我的模型<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> <div class="d-flex"> <div class="p-2 box box-red">Other content here</div> <div class="p-2 box box-blue">Some Other content here</div> </div> <div class="d-flex"> <div class="p-2 box box-green">Some Other content here</div> </div>没有为技能提供ApplicantSkillsVM,而Id

所以我的模特必须看起来像

nullable

问题已解决