Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No table is set Exception #123

Closed
PejmanNik opened this issue Aug 12, 2018 · 10 comments
Closed

No table is set Exception #123

PejmanNik opened this issue Aug 12, 2018 · 10 comments

Comments

@PejmanNik
Copy link
Contributor

Hi
We can have a query without 'from' like:

select '2' , '3'

throw new InvalidOperationException("No table is set");

@ahmad-moussawi
Copy link
Contributor

Could you elaborate more on the use case where you want this ?

@ahmad-moussawi
Copy link
Contributor

closing since long time with no reply, feel free to reopen if this still an issue for you

@mark-at-tusksoft
Copy link

mark-at-tusksoft commented Aug 23, 2019

@ahmad-moussawi
Found my way here from a google search as I am running into this issue currently.

I am populating a model in the format

public class SomeStatsObject {
    public int ThingsAlphaCount { get; set; }
    public int ThingsBetaCount { get; set; }
    public int ThingsGammaCount { get; set; }
    public int ThingsDeltaCount { get; set; }
}

that gets counts from a bunch of complex subqueries in the form of:

SELECT
    (SELECT COUNT (*) ...) ThingsAlphaCount,
    (SELECT COUNT (*) ...) ThingsBetaCount,
    (SELECT COUNT (DISTINCT *) ...) ThingsGammaCount,
    (SELECT COUNT (*) ...) ThingsDeltaCount,

I believe subqueries get what I need so my Sql Kata follows

var thingsAlphaCountSubQuery = new Query(); // example for type info 

 var mainQuery = new Query()
    .Select(thingsAlphaCountSubQuery, nameof(SomeStatsObject.ThingsAlphaCount))
    .Select(thingsBetaCountSubQuery, nameof(SomeStatsObject.ThingsBetaCount))
    .Select(thingsGammaCountSubQuery, nameof(SomeStatsObject.ThingsGammaCount))
    .Select(thingsDeltaCountSubQuery, nameof(SomeStatsObject.ThingsDeltaCount));

var compiledQuery = new SqlServerCompiler().Compile(new[] { someRawQueryForParams, mainQuery });

Thus, I get the 'No table is set' exception.

@rfink
Copy link

rfink commented Sep 16, 2019

Or when using "CROSS APPLY" for column reuse within the same query

@xavierzwirtz
Copy link

Similar issue as OP, would be nice to be able to run select SERVERPROPERTY('productversion')

@ahmad-moussawi
Copy link
Contributor

@xavierzwirtz db.Select("select SERVERPROPERTY('productversion')") is more appropriate here

@mark-at-tusksoft
Copy link

@ahmad-moussawi Could this be reopened? This is still an ongoing issue when compiling for SqlServer.

@mnsrulz
Copy link
Contributor

mnsrulz commented Jul 26, 2021

Or when using "CROSS APPLY" for column reuse within the same query

just curious if you able to tackle cross apply or outer apply with column reuse only

@jposert
Copy link

jposert commented Oct 27, 2021

Guys, you can just inherit your copiler class eg. SqlServerCompiler and override CompileFrom method like that:

public override string CompileFrom(SqlResult ctx)
{
    if (!ctx.Query.HasComponent("from", EngineCode))
    {
        return null;
    }

    return base.CompileFrom(ctx);
}

now query: new Query().Select("1 as Test");
won't throw any exception and returns SELECT [1] AS [Test] .

@mnsrulz
Copy link
Contributor

mnsrulz commented Nov 17, 2021

Guys, you can just inherit your copiler class eg. SqlServerCompiler and override CompileFrom method like that:

public override string CompileFrom(SqlResult ctx)
{
    if (!ctx.Query.HasComponent("from", EngineCode))
    {
        return null;
    }

    return base.CompileFrom(ctx);
}

now query: new Query().Select("1 as Test"); won't throw any exception and returns SELECT [1] AS [Test] .

this is really great..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants