devexpressxpo

XPODataSource: Select from TableValuedFunctions


Is it possible to select from a tabled-valued function using xpoDataSource instead of selecting from a table.

note: Im using xpoDatasource with serverMode = true


Solution

  • Source - Table Valued Function in XPO (and XAF)?

    You can accomplish this task via direct SQL queries. Here is an example:

    IDataLayer dal = XpoDefault.GetDataLayer(MSSqlConnectionProvider.GetConnectionString("(local)", "TestDatabase"), AutoCreateOption.None);
    Session session = new Session(dal);
    SelectedData data = session.ExecuteQueryWithMetadata("SELECT * FROM TrackingItemsModified(2)");
    XPDataView view = new XPDataView();
    foreach (var row in data.ResultSet[0].Rows) {
        view.AddProperty((string)row.Values[0], DBColumn.GetType((DBColumnType)Enum.Parse(typeof(DBColumnType), (string)row.Values[2])));
    }
    view.LoadData(new SelectedData(data.ResultSet[1]));
    GridControl control = new GridControl();
    control.DataSource = view;
    control.Dock = DockStyle.Fill;
    Form form = new Form();
    form.Controls.Add(control);
    form.ShowDialog();
    

    Reference these:
    How to populate an XPServerCollectionSource/InstantFeedbackCollectionSource with a runtime designed SQL statement result?
    How to pass a table valued parameter to Session.ExecuteSProc method