Pomelo.EntityFrameworkCore.MySql Database first and Generated column - mysql

in my table I have a Generated column of Decimal type,
COLUMN `quantidadeTotal` DECIMAL(18,4) GENERATED ALWAYS AS (((`quantidade` + `quantidadeReservada`) + `quantidadeBloqueada`)) VIRTUAL;
which is the sum of 3 other columns also of Decimal type, the problem occurs when I execute "scaffold", the generated model comes with this column in this format
public decimal? QuantidadeTotal { get; set; }
and in generated context also has reference to the
entity.Property(e => e.QuantidadeTotal)
.HasColumnName("quantidadeTotal")
.HasColumnType("decimal(18,4)");
column
if i try to insert some record in the table i get an error, even if not informing anything in the Generated column, i have to delete the reference of this column in the context and in the model to work.
is there any configuration for scaffold to ignore this type of column or any special treatment?
if not, every time I make a scaffold I will have to adjust all fields manually, and it would be a lot of work.
Pomelo.EntityFrameworkCore.MySql v3.2.4
thanks!

Thanks for reporting this bug on our repository as Database first and Generated column #1256!
We fixed it with:
3.2.x: Add scaffolding support for computed columns #1257
5.0.0+: Add scaffolding support for computed columns, including STORED support #1260

Related

hibernate converting char to binary

My JPA entity has a UUID attribute, which is stored as char(36) in mysql. When I query data i'm receving 66323735-3039-6262-2d31-3764392d3466 instead of f27509bb-17d9-4f37-b336-8603f2d34394. When I enabled hibernate logs, I could see
org.hibernate.type.descriptor.sql.BasicExtractor - extracted value ([col_1_0_] : [BINARY]) - [66323735-3039-6262-2d31-3764392d3466]
extracted value is [BINARY] instead of [VARCHAR] like other attributes.
Any clue as to why this is happening?
Also,
I've tried to run hibernate generated query on mysql and that returns correct results.
Other column values including UUIDs are being returned correctly.
I'm using an interface based entity projection to retrieve limited data and not the whole entity.
edit: I just added trim(colName) and now it's returning correct UUID value. But still not sure of the issue at hand.
Do this for hibernate 6. It will generate character type (for mysql char(36)).
#org.hibernate.annotations.JdbcTypeCode(SqlTypes.CHAR)
protected UUID id;

Support for MySQL timestamp in the POCO C++ libraries

The POCO libraries support MySQL DATE, TIME and DATETIME columns, but not TIMESTAMP. Selecting values from a TIMESTAMP column raises an "unknown field type" exception, since MYSQL_TYPE_TIMESTAMP is not supported in "Poco/Data/MySQL/ResultMetadata.cpp".
In my project I had to change several columns to DATETIME to make it work. This was not a big problem, still I wonder what the reason for this limitation is. If I had to work with an existing database schema that I couldn't alter, I'd be in serious trouble.
Timestamp columns are widely used, hence I don't believe they were simply omitted. Is there an implementation problem as to Timestamp columns? Is there a workaround I could use? Is it planned to add MySQL timestamp support to POCO in the future?
Download the source of POCO libraries then modify the file Data/MySQL/src/ResultMetadata.cpp
std::size_t fieldSize(const MYSQL_FIELD& field)
/// Convert field MySQL-type and field MySQL-length to actual field length
{
...
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP: // <-- add this line
return sizeof(MYSQL_TIME);
...
}
Poco::Data::MetaColumn::ColumnDataType fieldType(const MYSQL_FIELD& field)
/// Convert field MySQL-type to Poco-type
{
...
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP: // <-- add this line
return Poco::Data::MetaColumn::FDT_TIMESTAMP;
...
}
Compile the library and you will have support for TIMESTAMP fields.

Entity Framework Decimal Inconsistency

I'm implementing the tutorial http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/accessing-your-model's-data-from-a-controller
I use Entity Framework 4.1. In the database decimal value is mapped (18,2).
In the creating form I entered 1000 but in the details page the decimal value output is 1000,00 and also in the edit page as well.
I use #Html.EditorFor(model => model.Price) for input and for output.
When I looked at the database created by the Entity Framework the Price column which is my decimal value is created with this SQL command:
[Price] DECIMAL(18,2) NOT NULL
Why there is inconsistance?
You are comparing two different things. The mapping describes the precision which can be stored in the database but it has nothing to do with the way how your ASP.NET MVC View shows decimal number - it is handled by output formatting.

Entity Framework 4 - using DateTime2

I want Entity Framework to store all my dates as DateTime2 data type.
I have ProviderManifestToken="2008" in my SSDL and still all the generated dates are DateTime instead of DateTime2. What am I missing?
You are not missing anything. Entity framework never uses DataTime2 unless you manually modify its database generation process (only in model first approach). You need to update SSDLToSQL10.tt file to use DateTime2 instead of DateTime. Check the end of this answer for more details about modifying the template and configuring VS to use the new template.

SSIS casting error

Im getting a "An error occurred while attempting to perform a type cast" when using a derived column to format some error information. My Expression is a follows
(DT_STR,255,1252)("Insert Employee Error - EmployeeID:" + (DT_STR,255,1252)ID)
The ID column is an integer. Strangely enough i'm doing something similar in another package and this works fine. any ideas?
Heres my meta data passed to the derived column
I don't have any VMs handy for 2005 if that's your environment but the derived column transformation played looser with data types than 2008 so my test scenario, 2008 R2, ought to be valid regardless.
I see nothing wrong with your expression there. I spun up a quick package to verify your expectation that it works and it works for me.
Added a row with null value based on Siva's comment but does not appear to be the source of the OP's problem
A few things to check on the metadata preceding the derived column transformation
Is the casing of the column ID really ID?
Is the data type really 4 byte signed int? (DT_I4)
Try wrapping the ID column with [ID] or remove the ID completely and re-drag it from the Columns list