0

I`m using Entity Framwork and i have the next projection:

        var items = from mapsDsc in DbContext.MapsDesc
                    join mapCat in DbContext.MapsCategories on mapsDsc.MapID equals mapCat.MapID
                    join mainCat in DbContext.MainCategories on mapCat.MainCategory equals mainCat.MainCatID
                    join subCat in DbContext.SubCategories on mapCat.SubCategory equals subCat.SubCatID
                    select new DataModel.ComplexEntities.MapsDescExt
                    {
                        MapID = mapsDsc.MapID,
                        MapName = mapsDsc.MapName,
                        MapLink = mapsDsc.MapLink,
                        Note = mapsDsc.Note,
                        MainCategoryID = mapCat.MainCategory,
                        MainCategoryName = mainCat.Category,
                        SubCategoryID = mapCat.SubCategory,
                        SubCategoryName = subCat.Category
                    };

Please notice that this projection filling strong type and not anonymous one. I need to customize this projection a little bit but i don`t know how.

At my last join i need to implement the next condition with "or" operator:

join subCat in DbContext.SubCategories on mapCat.SubCategory equals subCat.SubCatID or subCat.SubCatID equals "0"

How can I do it? All the exampels I seen relate to anonymous types and it`s not good for me. Thanks

4

1 回答 1

0

You don't have to use the join syntax, you can do the same by a manual where and then slip in an extra condition:

var items = from mapsDsc in DbContext.MapsDesc
            join mapCat in DbContext.MapsCategories on mapsDsc.MapID
                                                equals mapCat.MapID
            join mainCat in DbContext.MainCategories on mapCat.MainCategory
                                                 equals mainCat.MainCatID
            from subCat in DbContext.SubCategories
/* here */  where mapCat.SubCategory == subCat.SubCatID || subCat.SubCatID == "0"
            select new DataModel.ComplexEntities.MapsDescExt
            {
            ...

(Note that mapCat.SubCategory should be an id field, you probably know which).

于 2013-03-31T00:01:16.323 回答