English 中文(简体)
• 如何与自治政府共同收集第一个项目
原标题:How to map the first item in a collection with AutoMapper

我的物体Foo gen d 和EF,它拥有一至多岁的Bar的导航财产,但应当是一对一。 不管怎么说,当我问一问一下Foo问题时,我也想从律师的收集中找到第一个和唯一的项目,并将这些物品描绘成一个被人 flat住的Biz Dto。

        var result = (from c in ctx.Foo
                     where c.Bar.Any(cs => cs.LOGINNAME == username && cs.PASSWORD == password)
        select c).First();

那么,在我的“自治”组合中,我就绘制了像样的地图?

        Mapper.CreateMap<Foo, Biz>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.CLIENTID))
            .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Bar.FirstOrDefault???))

Thank you, Stephen

最佳回答

http://www.un.org/Depts/DGACM/index_french.htm 在你绘制地图时收集:

opt.MapFrom(src => src.Bar.FirstOrDefault())
问题回答

鉴于:

public class Foo{
 public ICollection<Bar> Bars { get; set; }
}

解决办法:

var result = from item in FooCollection
             select new { FirstBar = item.Bars.FirstOrDefault() };

www.un.org/Depts/DGACM/index_spanish.htm

第1条

我认为......

HTH





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签