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

Get property which is calculated in select query #5109

Closed
Borlay opened this issue Apr 19, 2016 · 1 comment
Closed

Get property which is calculated in select query #5109

Borlay opened this issue Apr 19, 2016 · 1 comment

Comments

@Borlay
Copy link

Borlay commented Apr 19, 2016

I have plain sql with paging and search syntax, i want to execute it map tables to object and take total count. My code is like that:

var selectSql = " SELECT TotalCount = COUNT(*) OVER(), E.* FROM " + fullName + " E " + whereSql;
var rows = context.Set<EventTable>()
              .FromSql<EventTable>(selectSql, parameters.Select(p => p.Value).ToArray())
             .ToArray();
var totalCount = context.Entry(rows.First()).Property<int>("TotalCount").CurrentValue;

But i have problem when i trying to take property that not exist in database table. I don't need this property in a table, i just want to calculate it in select query. Why i can't do this?
In older version i can have class like below and map query into this class, in new framework its does not work because its throwing exception that entity of this type not found or something like that (don't remember now). If i add this new class in context, then its throwing new exceptions about discriminator property and etc.

[NotMapped]
public class EventSearchTable : EventTable
{
    [Column("total_count")]
    [Required]
    public int TotalCount { get; set; }
}
@Borlay Borlay changed the title Get property that are calculated in select Get property that are calculated in select query Apr 19, 2016
@Borlay Borlay changed the title Get property that are calculated in select query Get property which is calculated in select query Apr 20, 2016
@rowanmiller
Copy link
Contributor

The ability to map to classes/properties that are not part of the model/database is tracked by #1862 and is not currently implemented in EF Core.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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

3 participants