建体彩网|中彩网双色球连号|
?
快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

和記h188怡情:【Sharepoint教程Linq to Sharepoint】3、獲取Linq Query生成的CALM示例

?

我們知道Linq to sharepoint 實際終極照樣轉化成了CALM來對Sharepoint進行造訪,那么我們如何才能知道我們編寫的Query語句終極轉化成的CALM語句是什么樣子呢。我們可以應用如下措施來達到我們的目的。

1.首先在我們的Sharepoint項目中新建一個名為CAMLDebug的類,如圖:

CALMDebug.cs代碼如下:

using System;

using System.Collections.Generic; using System.Linq;

using System.Text; using System.IO;

using Microsoft.SharePoint.Linq;

namespace NorthwindLinqToSP {

public class CAMLDebug : IDisposable{

private DataContext _context;

public StringWriter Writer

{get;

private set;}

public CAMLDebug(DataContext和記h188怡情 context)

{_context = context;

Writer = new StringWriter();_context.Log = Writer;

}

public override string ToString()和記h188怡情{

Writer.Flush();return Writer.GetStringBuilder().ToString();

}

public void Dispose(){

_context.Log = 和記h188怡情null;Writer.Dispose();

}}

}

2.然后在我們的Linq to sharepoint 代碼中應用此類

var dc = new NorthWindEntityDataContext(SPContext.Current.Web.Url);

MyCustomers = dc.GetList("ACustomer");

MyOrders = dc.GetList("AOrders");

using (CAMLDebug debug = new CAMLDebug(dc)) {

string queries = debug.ToString();var query = from c in MyCustomers

where (from o in MyOrdersselect o.BCSFindCustomerID).Contains(c.BCSFindCustomerID)

select c;this.lblMsg2.Text = "Items :" + query.Count().ToString();

this.gvDetails.DataSource = query;

this.gvDetails.DataBind(); }

3.在代碼段中設置斷點,進入調試(當然,你也可以把queries保存的CALM字串輸出到你想要的任何地方)

4.此處,也有人不用上面的類,而直接應用如下代碼把天生的CALM直接輸出到指定的txt文件中進行查看。

var dc = new NorthWindEntityDataContext(SPContext.Current.Web.Url);

MyCustomers = dc.GetList("ACustomer");MyOrders = dc.GetList("AOrders");

TextWriter textWriter = new StreamWriter(@"c:caml.txt", false);

dc.Log = textWriter;

var query = from c in MyCustomerswhere !(from o in MyOrders

select o.BCSFindCustomerID).Contains(c.BCSFindCustomerID)select new

{CopanyName = c.BCSFindCompanyName,

ContanctName = c.BCSFindContactName,Address = new

{Country = c.BCSFindCountry,

City = c.BCSFindCity,PostalCode = c.BCSFindPostalCode

}

};

this.lblMsg2.Text = "Items :" + qu和記h188怡情ery.Count().ToString();this.gvDetails.DataSource = query;

this.gvDetails.DataBind();

上述代碼輸出的結果如下圖:

接下來的義務便是在你的SPQuery中進行引用了(以下是一個引用樣例,僅作參考)

SPQuery query = new SPQuery();

query.Query = @"

'ContentTypeId' />

'ContentTypeId'>0x0100

'ProductContentTypeId' />

'Lookup'>0x0100

'TRUE' />";

query.ViewFields = @"'Title' />'ProductProductName' />";

query.ProjectedFields = @"'ProductProductName' Type='Lookup'List='AProduct' ShowField='ProductName' />

'ProductContentTypeId' Type='Lookup'List='AProduct' ShowField='ContentTypeId' />";

query.Joins = @"'INNER' ListAlias='AProduct'>

'Product' RefType='ID' />'Product' Name='ID' />

";

query.RowLimit = 2657495668;

var list = web.Lists["AOr和記h188怡情ders"]; var items = list.GetItems(query);

foreach (SPListItem item in items) {

this.ListBoxOutPut.Items.Add(item["Title"]+ item["ProductProductName"])); }

免責聲明:以上內容源自網絡,版權歸原作者所有,如有侵犯您的原創版權請告知,我們將盡快刪除相關內容。

您可能還會對下面的文章感興趣:

建体彩网
陕西快乐十分8日走势图 体彩p5软件 快乐扑克 江苏7位数最新开奖l 脉动棋牌河南人的游戏 万能麻将作弊器免费版 华东15选5开奖 舟山棋牌游戏大厅 体彩6+1 排列三走势图11年五六月