Expose unique constrains metadata to schema API and T4 model
See original GitHub issueHi,
TT model generator sets correctly PrimaryKey attribute to properties of classes with attribute Table.
Would it be possible to add also a new attribute, named AlternateKey(string alternateKeyName)
, to identify properties that partecipate to a unique constraint?
For example:
[Table(Schema="DWUSER", Name="ST01_COMPONENT")]
public partial class ST01Component
{
[Column("ID_COMPONENT"), PrimaryKey, NotNull] public decimal IdComponent { get; set; } // NUMBER
[Column("SITE"), AlternateKey("ST01_NC_CODE_SITE_NC_CODE_UN"), Nullable] public string Site { get; set; } // NVARCHAR2(18)
[Column("SFC"), AlternateKey("ST01_NC_CODE_SITE_NC_CODE_UN"), Nullable] public string Sfc { get; set; } // NVARCHAR2(384)
[Column("ITEM"), Nullable ] public string Item { get; set; } // NVARCHAR2(384)
[Column("ITEM_DESCRIPTION"), Nullable ] public string ItemDescription { get; set; } // NVARCHAR2(120)
}
The use case is the possibility to use this new attribute to generate new code based on it without the need to call the back end database another time.
Thank you!
Environment details
linq2db version: 3.0.0-preview.1 Database Server: Oracle Database Provider: Oracle.ManagedDataAccess.Core (3.0.0-preview.1) Operating system: Windows 10 .NET Framework:.NET Core 3.1
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Defining Constraints and Indexes — SQLAlchemy 2.0 ...
Below we define a table invoice which has a composite primary key: invoice = Table( "invoice", metadata_obj, Column("invoice_id", Integer, primary_key=True) ...
Read more >How to change the behaviour of unique true in django ...
You can use a UniqueConstraint [Django docs] with a condition instead of the unique kwarg on the field. Although there is a caveat...
Read more >Constraints reference
... module create database constraints. They are added in the model Meta.constraints option. ... You must always specify a unique name for the...
Read more >Entity framework attributes. In the Choose Model Contents step
Whether the index is unique. Entity Framework 6 provides the [Index] attribute to create an index on a particular column in the database....
Read more >How do distributed databases follow unique constraints?
You need to choose some transactional model. It is key-value, SQL ACID transactions, Calvin transactions, something else? Different things will ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You need to add code to your
.tt
file (not to linq2db t4 templates) between model load and generation steps https://linq2db.github.io/articles/T4.html#example-of-generation-process-customizationand then go through Tables collection and add additional attributes to table columns.
You are right, a lack of time to implement. You can help us to retrieve Unique constraints by SchemaProvider. It can be good first PR.
Anyway
HasUniqueKey
helps to define unique constraint for the subquery, when you know which data returned by subquery.