This is a migrated thread and some comments may be shown as answers.

Force tablename on column in each SQL statement

0 Answers 39 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Olivier
Top achievements
Rank 1
Olivier asked on 05 Dec 2017, 02:31 PM

Hello 

I need calculated column on PostgreSql backend. It's work in almost case. 

I define my model like this:

public class MyEntity{
   public int IdMyEntity;
   public string Display;
   public int CalculatedColumn;
}
MappingConfiguration<MyEntity> configuration = new MappingConfiguration<MyEntity>();
configuration.MapType(x => new {
                IdMyEntity = x.IdMyEntity,
                Display = x.Display,
                CalculatedColumn = x.CalculatedColumn
}).WithConcurencyControl(OptimisticConcurrencyControlStrategy.None)
.WithCacheStrategy(CacheStrategy.Yes)
.ToTable("mytable");
configuration.HasProperty(x => x.IdMyEntity).ToColumn("idmyentity").WithDataAccessKind(DataAccessKind.ReadWrite).IsIdentity(KeyGenerator.Autoinc).IsNotNullable();
configuration.HasProperty(x => x.Display).ToColumn("display").WithDataAccessKind(DataAccessKind.ReadWrite).IsNullable();          
configuration.HasProperty(x => x.CalculatedColumn).ToColumn("calculatedcolumn").WithDataAccessKind(DataAccessKind.ReadOnly).IsNullable();

If I use this Linq

List<MyEntity> list = this.MyDatabase.MyEntitys;

ORM run this SQL statement : SELECT a."idmyentity" COL1, a."display" COL2, a."calculatedcolumn" COL3 FROM "mytable" a;

And that's work.

 

But if I use this Linq

MyEntity oneEntity = this.MyDatabase.MyEntitys.Where(x => x.IdMyEntity == 1);

ORM run this SQL statement : SELECT "idmyentity", "display", "calculatedcolumn" FROM "mytable" WHERE "idmyentity" = :p0;

And I have an error because Postgresql must have table name in prefix of column.

Have you a solution to add table name (or alias) in each SQL statement ?

Thanks in advance

Tags
General Discussions
Asked by
Olivier
Top achievements
Rank 1
Share this question
or