Query a table with TOM - Analysis Services C# - c#

I have a project of Net Core which it create database, tables and measures in a Tabular model. I would like to query some tables like we would do in SQL, for example, "select * from myTable". I've seen Microsoft documentation but I can't find an example that explains how to query a table of my tabular model. How can I do it? Could you give me an example?
I would like to query the cube and get a array like:
TableA.Column1
TableA.Column2
TableB.Column1
TableC.MeasureA
1
Marketing
Rosario
$999
2
Finance
Córdoba
$456

The DAX equivalent for SELECT is EVALUATE, the equivalent for
select * from myTable
is
evaluate 'myTable'

Related

Basic LINQ query to SQL C#

I have this LINQ query in C# for querying a db4o database.
IEnumerable<internetRecord> searchResult = from internetRecord ie in database
where ie.GSrecordID.Contains(txtSearchString.Text)
select ie;
What would be the equivalent query in SQL? (needed for comparison purposes) I have not worked with SQL much in the past and looking at it after using LINQ for a while it seems confusing.
SELECT *
FROM MyTable
WHERE GSRecordID LIKE '%txtSearchString%'
Select * from internetrecord where GSrecordID like '%your comparison string%'
Provided internetrecord is your SQL table GSrecordID is the column of your table.
I don't know much about db40 but in standard SQL it would be:
SELECT * FROM internetRecord
WHERE GSrecordID LIKE '%txtSearchString%'
YOu can do something like this
var result = database.Where(x => x.GSrecordID.Contains(txtSearchString.Text));

Query conceptual model with Entity SQL

My application is based on Entity Framework. I am offering users to query a particular table by saving their queries in another table. For example, TopQuery table in database stores all the queries which are popular among users.
These queries are performed on table "TableData"
For test purposed, I have tried the following and it works. The only problem is that it returns all columns where as I would like to use columns that are mentioned by users in their queries.
string queryString =
#"SELECT VALUE table FROM TestEntities.TableData AS table where table.col1 = 'test'";
ObjectQuery<TableData> productQuery2 =
new ObjectQuery<TableData>(queryString, context);
My problem is that if user stores a query in database like this, it doesn't work.
SELECT table.col1, table.col2, table.col3 FROM TestEntities.TableData AS table where table.col1 = "test"
I get the exception: The specified cast from a materialized System.Data.Objects.MaterializedDataRecord' to'TestEntities.TableData'type is not valid.
I have also tried this without any luck.
"SELECT it.col1, it.col2 FROM TableData WHERE it.col1 = 'test'"
What should I do in such case?
Regards,
You will never get ObjectQuery<TableData> once you try to select only subset of columns. Using ObjectQuery<TableData> works only when you select whole entity as your first query did - that is a strongly typed approach enforced by Entity framework.
ESQL doesn't support projection in the way Linq-to-entities does (by allowing you to project to a new anonymous or non mapped type). When using projection with ESQL you must work with ObjectQuery<DbDataRecord>.

Linqer dont Convert T-Sql query

I using linqer want this sql to liqn query but i have problem
select * from Project where Id in (select Top 3 ForeignId from ActivityLog
group by ForeignId order by count(*) desc)
Problem :SQL cannot be converted to LINQ: Field [Id in (select Top 3 ForeignId from ActivityLog group by ForeignId order by count(*) desc)] not found in the current Data Context.
I just had a similar issue with linqer. I found the solution was removing the ; after the SQL query and trying again.
It could be an issue with your context.
See Linqer – a nice tool for SQL to LINQ transition for instructions on setting up the context.
Also, make sure the *.dbml and *.designer.cs files are up to date and define the Project table to contain an Id column and the ActivityLog table to contain a ForeignId column.
This could be a bug with the version of linqer you are using. I am using 4.0.3 and was able to run the same query (adjusted to use my tables) without issue.

C# Access Database Question

Say i have 2 tables now, PricePlan and Bill. Both tables have a column called 'Price' and I would like the table 'Bill' to update the value from 'PricePlan's Price. How can i do this or what SQL statement should i be using? Thanks in advance!
You will need to have some sort of way to define a relationship between the two tables.
For instance if your tables have this structure:
PricePlan
---------
ID
Price
Bill
---------
PricePlanID
Price
This will only work for SQL Server. See below for Access solution.
Then a query like this should update Bill :
UPDATE b SET b.Price = pp.Price
FROM Bill as b
INNER JOIN PricePlan as pp
ON b.PricePlanID = pp.id
Also, the schema above is only for example purposes. If yours is like that you should look at changing it.
UPDATE
I just noticed this is for Access, sorry. The strucure of your query will be slightly different. See below:
UPDATE Bill INNER JOIN
PricePlan ON Bill.PricePlanID = PricePlan.ID
SET Bill.Price= [PricePlan].[Price];
making some wide assumptions here, but i think this short tutorial on cascading updates in access 2010 should get you on your way.

Get Database's Tables

I want to write a query to get the names of tables of a specific database, but I don't know how can write it.
I want to execute this query for MS Access 2007 and Oracle 11g.
Thanks
If you want raw, direct queries:
For Oracle:
SELECT * FROM user_tables
For MS Access:
SELECT * FROM MSysObjects WHERE [Type] In (1, 4, 6)
(sorting and advanced filtering omitted for brevity.)

Categories

Resources