Entity framework 如何从实体框架中调用的子对象中删除重复数据?

Entity framework 如何从实体框架中调用的子对象中删除重复数据?,entity-framework,entity-framework-6,lazy-loading,eager-loading,Entity Framework,Entity Framework 6,Lazy Loading,Eager Loading,这是正确的做法。试试这个,这对我来说很好用。由于无法使用Include()进行过滤,因此必须使用投影技术。您的模型看起来如何?你所说的是什么意思?我已经多次得到它了。早些时候,我使用了Include(),它不允许对数据进行过滤,所以我切换到了投影方法,得到了期望的结果。我的代码-var eventDetails=(从db.tb_事件中的e选择new{e.EventID,e.tb_Customer.CustomerName,e.StartDate,e.EndDate,loc=(从db.tb_事件位

这是正确的做法。试试这个,这对我来说很好用。由于无法使用Include()进行过滤,因此必须使用投影技术。

您的模型看起来如何?你所说的
是什么意思?我已经多次得到它了。早些时候,我使用了Include(),它不允许对数据进行过滤,所以我切换到了投影方法,得到了期望的结果。我的代码-var eventDetails=(从db.tb_事件中的e选择new{e.EventID,e.tb_Customer.CustomerName,e.StartDate,e.EndDate,loc=(从db.tb_事件位置中的l选择new{l.tb_Location.LocationName}.Distinct(),e.Objective});哇!很好的解决方法,你为什么不把它发布在答案部分?@BagusTesa我已经添加了它。嗯,等等,我的意思是。。不编辑您的问题,但将其写在答案部分。。
            var eventDetails = (from e in db.tb_Event                            

                            select new
                            {
                                e.EventID,
                                e.tb_Customer.CustomerName,
                                e.StartDate,
                                e.EndDate,
                                loc = (from l in db.tb_EventLocation where l.EventID == e.EventID select new { l.tb_Location.LocationName }).Distinct(),
                                e.Objective

                            });