6/27/2025 11:29:05 PM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
|
|
|
|
Issue joining a tables using the Repository to build a query
Posted: 22 Dec 09 3:58 PM
|
I am using the following code to Query the Opportunity_Products table. I am using it to bind to a data source that will be shown on a grid, but I also need to see data from the product table. How can I join the product table in so I can use the view its information in my grid as well?
Sage.Entity.Interfaces.IOpportunity myOpp = (Sage.Entity.Interfaces.IOpportunity)GetParentEntity(); Sage.Platform.Repository.IRepository repository = Sage.Platform.EntityFactory.GetRepository(); Sage.Platform.Repository.IQueryable qry = (Sage.Platform.Repository.IQueryable)repository; Sage.Platform.Repository.IExpressionFactory ef = qry.GetExpressionFactory(); Sage.Platform.Repository.ICriteria criteria = qry.CreateCriteria(); criteria.Add(ef.Eq("Opportunity", myOpp)); dgOppoProd.DataSource = criteria.List(); dgOppoProd.DataBind();
I tried to use the following but with no luck: 1) "criteria.SetFetchMode("Product", FetchMode.default);" and 2) "criteria.CreateAlias("Product", "pr"); criteria.Add(Expression.EqProperty("pr.Name", "pr.Description") );"
Thanks for any help!
|
|
|
|
Re: Issue joining a tables using the Repository to build a query
Posted: 23 Dec 09 9:54 AM
|
Not sure that I am following all the code here, so don't rely completely on my advice, but at least give it a try:
IRepository repository = EntityFactory.GetRepository(); //I specify the Interface type for the Repository. IQueryable qry = (IQueryable)repository; IExpressionFactory ef = qry.GetExpressionFactory(); ICriteria criteria = qry.CreateCriteria(); criteria.Add(ef.Eq("Opportunity", myOpp));
When you execute "criteria.List();" you get a list of IOpportunityProduct object, you should be able to address fields from the Product table. Adding an Alias is just to help you address fields from each object, so rather than binding to Object.Product.Name you could bind to pr.Name.
|
|
|
|
Re: Issue joining a tables using the Repository to build a query
Posted: 23 Dec 09 10:21 AM
|
Thanks. You seem to understand exactly what I am trying to do.
When I Added the Alias and then tried to call pr.Name I get an error that pr.Name is invalid. It seems with what I have above I can only get access to OpportunityProduct fields.
I have tried to used the Alias and I have tried to call it directly with Product.Name. Both ways I get an error that the field isn't in my dataset.
I didn't try with the object.Product.name. What 'object' are you referring to? For the other fields I just called them by name. "Price" or "Status" |
|
|
|
Re: Issue joining a tables using the Repository to build a query
Posted: 28 Dec 09 3:34 PM
|
I was finally able to get the grid to show items from the Products table by doing the following. I could never get the Repository to show joined tables.
Sage.Entity.Interfaces.IOpportunity myOpp = (Sage.Entity.Interfaces.IOpportunity)GetParentEntity(); Sage.Platform.Data.IDataService _dataService = ParentWorkItem.Services.Get(); System.Data.DataTable table = new System.Data.DataTable(); string sql = "Select pr.Name, op.Price, op.Status From Opportunity_Product op Join Product pr on op.ProductID = pr.productID Where OpportunityID = '" + myOpp.Id.ToString() + "'"; using (System.Data.OleDb.OleDbConnection conn = (System.Data.OleDb.OleDbConnection)_dataService.GetConnection()) { conn.Open(); System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(sql, conn); adapter.Fill(table); }
dgOppoProd.DataSource = table; dgOppoProd.DataBind();
Thanks, Ronnie |
|
|
|
Re: Issue joining a tables using the Repository to build a query
Posted: 29 Jun 12 3:54 PM
|
fiogf49gjkf0d If I am doing this in a C# .Net Code Snippet ( a business rule)....how do you pass the table object back to the calling form script......the business rule can pass the IList of an NHibernate Query....but the table (System.Data.DataTable) which you apply so easily to the datagrid at the form script level needs to be converted to the correct IList? |
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|