1

私は Microsoft Dynamics CRM 2011 を使用しています。ここには、permitCounty に関連する許可と permits ae を持つ一連のアカウントがあり、permitCounty は County に関連しています。

このクエリのような出力を取得したいと思います。

しかし、それは適切ではありません

strSearch="Some text";

var lstItems = (from county in x.De_countySet
                join permitcounty in x.de_permitcountySet on county.De_countyId equals permitcounty.de_CountyId.Id
                join permit in x.de_permitSet on permitcounty.de_PermitId.Id equals permit.de_permitId
                join account in x.AccountSet on permit.de_AccountId.Id equals account.AccountId into outer

                where permit.de_Type.Equals("Type1") && permit.statuscode.Equals("Active")                // Permit Type as Type1 and Status as Active
                where account.De_LegalName.Contains(strSearch) || account.Name.Contains(strSearch)        // Search in Legal Name and Account full name
                where county.de_CountyName.Contains(strSearch)                                            // Search in County Name

                orderby county.de_CountyName
                from account in outer.DefaultIfEmpty()
                select new clsTemp
                {
                    Name = account.Name,
                    De_LegalName = account.De_LegalName,
                    Address1_Line1 = account.Address1_Line1,
                    Address1_City = account.Address1_City,
                    Address1_PostalCode = account.Address1_PostalCode,

                    de_CountyName = county.de_CountyName              
                 }).ToList();

どんな助けでも大歓迎です。

ヴィーヌ

4

1 に答える 1

0

グループ結合を記述する別の方法を次に示します。into以下を含む行のみが置き換えられた行であることに注意してください。

strSearch="Some text";

var lstItems = (from county in x.De_countySet
                join permitcounty in x.de_permitcountySet on county.De_countyId equals permitcounty.de_CountyId.Id
                join permit in x.de_permitSet on permitcounty.de_PermitId.Id equals permit.de_permitId
                let outer = x.AccountSet.Where(account => permit.de_AccountId.Id == account.AccountId)

                where permit.de_Type.Equals("Type1") && permit.statuscode.Equals("Active")                // Permit Type as Type1 and Status as Active
                // "account" is not in scope and should cause a design-time error
                where account.De_LegalName.Contains(strSearch) || account.Name.Contains(strSearch)        // Search in Legal Name and Account full name
                where county.de_CountyName.Contains(strSearch)                                            // Search in County Name

                orderby county.de_CountyName
                from account in outer.DefaultIfEmpty()
                select new clsTemp
                {
                    Name = account.Name,
                    De_LegalName = account.De_LegalName,
                    Address1_Line1 = account.Address1_Line1,
                    Address1_City = account.Address1_City,
                    Address1_PostalCode = account.Address1_PostalCode,

                    de_CountyName = county.de_CountyName              
                 }).ToList();

このように書くと、明らかなエラーが明らかになります (account範囲外)。おそらく他の問題もあります。許可のない郡は表示されませんが、アカウントを持たない複数の許可を持つ郡には、空白のアカウントを持つ複数の行が表示されます。これはあなたが望む機能ですか?

編集: 2回目の試行:

strSearch="Some text";

var lstItems = (from county in x.De_countySet
                join permitcounty in x.de_permitcountySet on county.De_countyId equals permitcounty.de_CountyId.Id
                join permit in x.de_permitSet on permitcounty.de_PermitId.Id equals permit.de_permitId


                where permit.de_Type.Equals("Type1") && permit.statuscode.Equals("Active")                // Permit Type as Type1 and Status as Active

                where county.de_CountyName.Contains(strSearch)                                            // Search in County Name

                orderby county.de_CountyName
                from account in x.AccountSet.Where(account => 
                    permit.de_AccountId.Id == account.AccountId &&
                    (account.De_LegalName.Contains(strSearch) || 
                     account.Name.Contains(strSearch))).DefaultIfEmpty()   // Search in Legal Name and Account full name
                select new clsTemp
                {
                    Name = account.Name,
                    De_LegalName = account.De_LegalName,
                    Address1_Line1 = account.Address1_Line1,
                    Address1_City = account.Address1_City,
                    Address1_PostalCode = account.Address1_PostalCode,

                    de_CountyName = county.de_CountyName              
                 }).ToList();
于 2012-10-19T19:15:29.113 に答える