本文整理汇总了C#中ServiceContext.CreateQuery方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceContext.CreateQuery方法的具体用法?C# ServiceContext.CreateQuery怎么用?C# ServiceContext.CreateQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceContext
的用法示例。
在下文中一共展示了ServiceContext.CreateQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindByName
public object FindByName(string entity, string nameField, string name)
{
using (OrganizationServiceProxy proxy = CRMHelper.Connect())
{
ServiceContext context = new ServiceContext(proxy);
return (from s in context.CreateQuery(entity)
where s[nameField] == name
select s).FirstOrDefault();
}
}
示例2: LookupMaterial
public void LookupMaterial()
{
using (OrganizationServiceProxy proxy = CRMHelper.Connect())
{
ServiceContext context = new ServiceContext(proxy);
Entity entity = (from it in context.CreateQuery("new_invoicetype")
where it["new_typeidinvoice"] == "07"
select it).FirstOrDefault();
Console.WriteLine(entity.Id);
}
}
示例3: Find
public string Find(string entity, string idField, string id, string field)
{
object value;
using (OrganizationServiceProxy proxy = CRMHelper.Connect())
{
ServiceContext context = new ServiceContext(proxy);
value = (from s in context.CreateQuery(entity)
where s[idField] == id
select s[field]).FirstOrDefault();
}
return value as string;
}
示例4: Run
//.........这里部分代码省略.........
Console.WriteLine("==============================================");
foreach (var record in query)
{
Console.WriteLine("Contact Name: {0} {1}",
record.Contact.FirstName, record.Contact.LastName);
Console.WriteLine("Account Phone: {0}",
record.Account.Address1_Telephone1);
}
//</snippetUseLinqQuery3>
Console.WriteLine("<End of Listing>");
Console.WriteLine();
//OUTPUT:
//Join account and contact
//List all records matching specified parameters
//Contact name: Wilcox or Andrews
//Account area code: 206 or 425
//==============================================
//Contact Name: Ben Andrews
//Account Phone: (206)555-5555
//Contact Name: Ben Andrews
//Account Phone: (425)555-5555
//Contact Name: Colin Wilcox
//Account Phone: (425)555-5555
//<End of Listing>
// Build a complex query with LINQ. This query includes multiple
// JOINs and a complex WHERE statement.
//<snippetUseLinqQuery4>
var complexQuery = from c in svcContext.ContactSet
join a in svcContext.AccountSet
on c.ContactId equals a.PrimaryContactId.Id
join l in svcContext.CreateQuery<Lead>()
on a.OriginatingLeadId.Id equals l.LeadId
where c.LastName == "Wilcox" || c.LastName == "Andrews"
where a.Address1_Telephone1.Contains("(206)")
|| a.Address1_Telephone1.Contains("(425)")
select new
{
Contact = new Contact
{
FirstName = c.FirstName,
LastName = c.LastName,
},
Account = new Account
{
Address1_Telephone1 = a.Address1_Telephone1
},
Lead = new Lead
{
LeadId = l.LeadId
}
};
Console.WriteLine("Join account, contact and lead");
Console.WriteLine("List all records matching specified parameters");
Console.WriteLine("Contact name: Wilcox or Andrews");
Console.WriteLine("Account area code: 206 or 425");
Console.WriteLine("==============================================");
foreach (var record in complexQuery)
{
Console.WriteLine("Lead ID: {0}",
record.Lead.LeadId);
Console.WriteLine("Contact Name: {0} {1}",
record.Contact.FirstName, record.Contact.LastName);
示例5: Notify
public void Notify(Toyota.Tsusho.CRM.API.MessageContracts.OrderNotifyRequestMessage request)
{
using (OrganizationServiceProxy proxy = CRMHelper.Connect())
{
ServiceContext context = new ServiceContext(proxy);
foreach (OrderItemDataContract item in request.Items)
{
bool add = false;
Entity entity = null;
Invoice record = (from a in context.InvoiceSet
where a.new_saporderno == item.Invoice.new_saporderno
select a).FirstOrDefault();
if (record == null)
{
add = true;
record = new Invoice();
}
//CustomerId Lookup
Contact contact = (from c in context.ContactSet
where c.new_customeraccountnumber == item.Invoice.CustomerId.Name
select c).FirstOrDefault();
if (contact == null)
throw new Exception(String.Format("No Contact could be retrieved for {0}", item.Invoice.CustomerId.Name));
//SalesOrder
SalesOrder order = null;
if (item.Invoice.SalesOrderId != null)
{
order = (from o in context.SalesOrderSet
where o.new_DBMOrderNumber == item.Invoice.SalesOrderId.Name
select o).FirstOrDefault();
}
//SalesOffice
Territory salesOffice = null;
if (item.Invoice.new_salesoffice != null)
{
entity = (from s in context.CreateQuery("territory")
where s["new_sapcode"] == item.Invoice.new_salesoffice.Name
select s).FirstOrDefault();
if (entity != null)
salesOffice = entity.ToEntity<Territory>();
}
//Plant
entity = (from p in context.CreateQuery("territory")
where p["new_sapcode"] == item.Invoice.new_plant.Name
select p).FirstOrDefault();
Territory plant = null;
if(entity != null)
plant = entity.ToEntity<Territory>();
//new_invoicetype
new_invoicetype invoiceType = null;
if(item.Invoice.new_invoicetype != null)
{
entity = (from it in context.CreateQuery("new_invoicetype")
where it["new_typeidinvoice"] == item.Invoice.new_invoicetype.Name
select it).FirstOrDefault();
if(entity != null)
invoiceType = entity.ToEntity<new_invoicetype>();
}
//Populate Order Fields
record.new_saporderno = item.Invoice.new_saporderno;
record.new_client = item.Invoice.new_client;
if (contact != null)
record.CustomerId = contact.ToEntityReference();
if (order != null)
record.SalesOrderId = order.ToEntityReference();
record.new_precedingdocument = item.Invoice.new_precedingdocument;
if (salesOffice != null)
record.new_salesoffice = salesOffice.ToEntityReference();
if(plant != null)
//.........这里部分代码省略.........