question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySQL - Virtual Column not handled in INSERT, UPDATE

See original GitHub issue

Please consider the following table:

CREATE TABLE `products` (
  `ProductID` int(11) NOT NULL,
  `ProductName` char(255) NOT NULL,
  `data` json NOT NULL,
  `jsonID` int(11) GENERATED ALWAYS AS (json_extract(`data`,'$.jsonID')) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

if I retrieve data from the DB, linq2sql behaviour is normal, but if I InsertOrReplace and item, this exception is fired: “The value specified for generated column ‘jsonID’ in table ‘products’ is not allowed” It happens because the MySQL connector tries to set a value in a column that is virtually generated (alias read-only). Please add a property attribute such as “ReadOnly” or “Virtual” that we can apply to the C# class to indicate linq2db that the column should not be inserted in the INSERT or UPDATE queries, but only in the SELECT query Thanks in advance, Luca

C# Class implementation

[Table(Name = "Products")]
    public class Product
    {
        [PrimaryKey]
        public int ProductID { get; set; }

        [Column(Name = "ProductName"), NotNull]
        public string Name { get; set; }

        [Column(Name = "data")]
        public string data { get; set; }

        [Column(Name = "jsonID")]
        public int jsonID { get; internal set;}
    }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Eykhlercommented, Oct 31, 2016

Try to use ColumnAttribute boolean properties: SkipOnInsert and SkipOnUpdate.

0reactions
sdanylivcommented, Apr 23, 2017

@visual1993, it is not a bug, this attribute works for different configurations. But i agree it would be great to throw informative exception that for the same configuration two attributes are defined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mysql - INSERT INTO ... SELECT if destination column has ...
SELECT if the destination table adds some columns where some of them are GENERATED? The code calling this query is generic and has...
Read more >
Virtual Columns and Effective Functional Indexes in InnoDB
The virtual columns are no longer materialized in the table. ... virtual columns when they need to be materialized (e.g. INSERT or UPDATE...
Read more >
13.1.20.8 CREATE TABLE and Generated Columns
VIRTUAL : Column values are not stored, but are evaluated when rows are read, immediately after any BEFORE triggers. A virtual column takes...
Read more >
13.1.9.2 ALTER TABLE and Generated Columns
Virtual generated columns cannot be altered to stored generated columns, or vice versa. To work around this, drop the column, then add it...
Read more >
Generated columns (virtual & stored) do not update on ...
Description: I have an original replication setup consisting of two OLTP mysql instances (5.7.31 on Centos 7) and two OLAP (5.7.30 on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found