score:1
Accepted answer
You can do that with a UNION query. EG
var q = db.Books.GroupBy(g => "Books").Select(g => new { Name = g.Key, EntryCount = g.Count() })
.Union(db.Authors.GroupBy(g => "Authors").Select(g => new { Name = g.Key, EntryCount = g.Count() }));
var r = q.ToList();
score:1
Not an EF guy, and not sure if this would be more performant.
Select TableName = o.name
,RowCnt = sum(p.Rows)
From sys.objects as o
Join sys.partitions as p on o.object_id = p.object_id
Where o.type = 'U'
and o.is_ms_shipped = 0x0
and index_id < 2 -- 0:Heap, 1:Clustered
--and o.name in ('Table1','Table2','Table3' ) -- Include (or not) your own filter
Group By o.schema_id,o.name
Note: Wish I could recall the source of this, but I've used it in my discovery process.
Source: stackoverflow.com
Related Query
- Linq equivalent of aggregate function on multiple tables in one database trip
- Call a Linq to SQL user defined function multiple times in one trip to the DB
- convert SQL query with multiple join on multiple tables using group by on multiple columns and with aggregate function into LINQ
- LINQ to SQL: Complicated query with aggregate data for a report from multiple tables for an ordering system
- How to reuse a linq expression for 'Where' when using multiple source tables
- Joining two tables and returning multiple records as one row using LINQ
- Pull data from multiple tables in one SQL query using LINQ and Entity Framework (Core)
- LINQ Group By multiple table Inner Join and aggregate function
- Insert into multiple tables (one to one relationships) with Linq queries and SQLite
- CLRSQL Aggregate function. LINQ Code works within CLR Function but cannot be deploy within Aggregate
- LINQ Group by on multiple tables with nested group by with join and aggregate
- How to get entities from multiple tables with one LINQ call?
- LINQ aggregate multiple tables
- How to sort list on multiple properties in one line of code in Linq
- Joining or Including multiple tables with Entity Framework Core LINQ to Entities - One to Many and then Many to One
- Multiple aggregate functions in one query using Linq to SQL
- Using linq to select possible values for multiple database columns in one SQL query (EF6)
- Search multiple tables with no relation by special value with one query using linq to entity
- Running multiple linq queries on single model in one function
- Struggling to convert SQL query to it's LINQ equivalent - Multiple joins, groupings and aggregate functions
- How to select from multiple tables using LINQ using a union query to return only one column?
- add all rows of multiple tables into one and group using linq
- How to convert multiple join associated with aggregate function Linq to sql C#?
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How to perform Join between multiple tables in LINQ lambda
- LINQ to SQL multiple tables left outer join
- Creating a LINQ select from multiple tables
- Group Multiple Tables in LINQ
More Query from same tag
- Linq query can't be converted to SQL: how to optimize the code?
- LINQ, Visual Basic, & Reflection: capitalization of field names from queries returning anonymous type
- LINQ anonym object with result to delimited string (LINQ to Entities does not recognize the method 'System.String ToString()' method)
- rework linq query to returns nested objects
- ASP.NET MVC: How to search decimal value?
- Sorting NHibernate query results
- Linq Where local counter closure different results in VS watch
- Dicionary intersect keys with list and get in result dicionary with values at the beggining LINQ
- ASP.NET Entity Framework LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)
- LINQ statement with 2 inner joins
- using linq query to find value that differs from previously found value
- How to query SQL by month & id to get SUM
- Filter Object List with string array list C# lambda expression
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Binding data from database to a label control in asp.net
- EF5 Select objects based on child collection content
- How to combine a dictionary and list by key
- How to use Linq to join multiple DataTables on multiple columns containing DBNull values
- LINQ Query Issue, Sequence contains no elements
- Generic LINQ orderby lambda function
- Entity Framework Core LINQ Class Property/Methods can't use Included Property
- Linq Expression to generic - how
- Programmatically Add Row to Linq-to-SQL Dataset
- Using LINQ how do I have a grouping by a "calculated field"
- Linq query for Where condition on Collection of variant object's property
- Complex LINQ request and odd int increment behavior
- algorithm challenge: merging date range
- Hitting the 2100 parameter limit (SQL Server) when using Contains()
- how concatenate multiple rows in LINQ with two tables?
- Select database entity depending of one of its datetime columns value