Questions tagged [sql-generation]
17 questions
14
votes
1 answer
Entity Framework 6: How to override SQL generator?
I'd like to amend the SQL that's being generated by EF:CF when generating the database schema (DDL), as suggested by the Entity Framework team.
How can this be done?
I couldn't find anything appropriate via Google.

AxD
- 2,714
- 3
- 31
- 53
9
votes
3 answers
Why does EntityFramework's LINQ parser handle an externally defined predicate differently?
I'm using Microsoft's Entity Framework as an ORM and am wondering how to solve the following problem.
I want to get a number of Product objects from the Products collection where the Product.StartDate is greater than today. (This is a simplified…

Joe Fawcett
- 307
- 2
- 7
8
votes
1 answer
Entity Framework 6: Migration Drop column if exists
During a migration operation to drop a column, how can one generate SQL to check for the column's existence first before attempting to drop it?
For a drop column operation Entity framework currently generates sql like this to drop a column:
//…

Hans Vonn
- 3,949
- 3
- 21
- 15
5
votes
3 answers
EF Code First adds extra column to query that doesn't exist in model anymore
This is my first question on SO.
I have an ASP.NET 4.0 MVC3 project that is using EF Code First as ORM and FluentMigrator for version migrations. And there I have Message entity class that looks like this:
public class Message
{
[Key]
…

Andrii M4n0w4R
- 178
- 2
- 11
2
votes
1 answer
JOOQ: generating update SQL for table named by String
I just want to use JOOQ to generate SQL without it validating tables, columns, etc., and without it generating classes for said tables, columns, etc.
How can I generate a SQL update, and just specify the name of the schema & table with…

XDR
- 4,070
- 3
- 30
- 54
2
votes
3 answers
SQL::Abstract generate insert with select query
insert into table1(id, text) select (max(id)+1), "Something" from table1
How to generate this query with SQL::Abstract or SQL::Abstract::More?

edem
- 3,222
- 3
- 19
- 45
1
vote
4 answers
Find min value and max value from two columns. Generate date from min to max
I have table in SQL Server DB:
ID Open_date Close_date
1 01-01-2010 01-03-2010
2 21-01-2011 12-02-2011
3 01-03-2010 NULL
4 10-01-2010 NULL
I need to make some T-SQL query that will return:
Month Year Open …

sunprophit
- 1,639
- 4
- 16
- 39
1
vote
1 answer
Entity Framework 6 bad SQL generation and performance while grouping and aggregating
I have a case where I can't make Entity Framework build nice and fast sql for me.
My case is that I have three entities. Shop, Sale and SalesLine.
Sale holds a transaction datetime, and the salesline holds quantity, prices etc.
I want to build a…

MLNDK
- 85
- 1
- 8
1
vote
1 answer
Best practices to Minimize/Manage SQL string blobs in data access code (e.g. Dapper)
I've built some data layers using Dapper with great pleasure. Of course maintaining the required SQL strings can be an issue, especially when the db schema changes (rename column etc).
I'm looking for a strategy to "remove" most SQL string blobs…

smv
- 585
- 5
- 12
1
vote
1 answer
Doctrine SQL/table generation failing
I am trying to make Doctrine generate SQL from a set of models that I created earlier with a YAML schema. Using the code below which comes from the manual the output should be a set of queries.

Evert
- 376
- 2
- 10
1
vote
1 answer
How generate the SQL queries that match the JPA Entity CRUD operations at build time with Hibernate
Given JPA annotated Entities, is it possible to generate (i.e. before runtime) the list of queries that will be performed by Hibernate for CRUD operations (performed against EntityManager) ?
For named queries it is possible using…

snowflake
- 1,750
- 2
- 17
- 40
1
vote
2 answers
Writing a SQL generator, What Should I Read Up On?
I am soon going to be writing a component that takes metadata and generates dynamic SQL from it. Mostly we're talking SELECT, INSERT, UPDATE, DELETE stuff but I suppose it's possible to have some CREATE/ALTER TABLE statements in there too.
I'm…

George Mauer
- 117,483
- 131
- 382
- 612
0
votes
0 answers
EF Core Mapping Entities to Models
I'm trying to efficiently map entities on to models.
My entities are:
public class ParentEntity
{
public int Id { get; set; }
public string Name { get; set; }
public ChildEntity Child { get; set; }
}
public class ChildEntity
{
…

Jasper Kent
- 3,546
- 15
- 21
0
votes
0 answers
How to generate SQL for Oracle 11g with Liquibase 3.3 in offline mode?
Problem
I use YAML scripts that describes my DB objects structure. It is very convenient because I can have DB-based integration tests with H2.
But the Production service of my client requires that we provide Oracle oriented SQL scripts (they use…

Jérémy Buget
- 168
- 2
- 11
0
votes
1 answer
Generating random data sql server 2008 (firstName Surname address etc..)
Because of some testing I need to do I need to generate a database with 400000 records
I have done that with a simple
"WHILE @RowCount <= @NumberRecords" etc..
My issue is how do I generate some sort of unique FirstName,Surname and…

user9969
- 15,632
- 39
- 107
- 175