Comments (7)
I've several Questions.
MinLength: This is done by something like this nvarchar(x, y)
. Just one parameter means "max" but which is "min" and which is "max" if you use two?
DatabaseGenerated: I assume you are talking about this DatabaseGenerated(DatabaseGeneratedOption.Computed)
right? If yes, how should it behave (with other word, how should it be reflected in the generated SQLite DDL)?
Timestamp: This should do this ColumnName DATETIME DEFAULT (CURRENT_TIMESTAMP)
right?
NotMapped: If I annotate a property with [NotMapped]
its not created. What should be implemented?
from sqlitecodefirst.
You are right, I've tested all this annotations...
NotMapped: Is working.
MinLength: Is working too (does nothing, but you can use it with MVC).
DatabaseGenerated: Is working (None
and Identity
). I was only a little bit confused, that Identity
is obviously the implicit mode. With Computed
you get an error and the suggestion to use Identity
. - This is ok.
from sqlitecodefirst.
Timestamp: Is not working...
It is not about a date. To explain: We are using SQL Server and also SQLite. If you use something like this
[Timestamp]
public byte[] Timestamp { get; set; }
you get a correct Timestamp-column on SQL Server, but a crash (no db-generation) on SQLite. I don't know how we can solve this. Maybe ignoring on SQLite?
from sqlitecodefirst.
NotMapped: Will add it to the supported list
DatabaseGenerated: Will add it to the supported list
MinLength: Yes currently is just ignored and it will also not have any meaning if its added because SQLite will just ignore max and min. But as "max" is supported "min" should also be supported (it has no impact to the behavoir but if you have a look at the database, its there, for documentation, which is a good thing). Here my problem is that I don't find anything about the min/max stuff. Do you know what is min and max if I have a SQLite Command like this "NVARCHAR(x, y)"?
Timestamp: The problem with this is that, as soon as I add the "Timestamp" annotation to a property, my Initializer don't get called. I have no idea why.. So it does not crash because of my code. If the initializer would be called and it does not know an annotation, this annotation is just ignored.
from sqlitecodefirst.
MinLength: I think it is only useful for validation in MVC. In my opinion it makes no sense to have such a constraint in the database. This "idea" is really new to me...
Timestamp: You are absolutely right, it is ignored. I also have no idea why...
from sqlitecodefirst.
The cause of the "Timestamp" problem is the TimestampAttributeConvention
as a workaround you can use modelBuilder.Conventions.Remove<TimestampAttributeConvention>();
on the OnModelCreating
method from the DbContext. Of course, in your case, you need to dedect which Db is used (SQL-Server or SQLite).
Here is what this convention does.
public override void Apply(ConventionPrimitivePropertyConfiguration configuration, TimestampAttribute attribute) { Check.NotNull<ConventionPrimitivePropertyConfiguration>(configuration, "configuration"); Check.NotNull<TimestampAttribute>(attribute, "attribute"); configuration.IsRowVersion(); }
Where IsRowVersion will do the following:
/// <summary> /// Configures the property to be a row version in the database. /// The actual data type will vary depending on the database provider being used. /// Setting the property to be a row version will automatically configure it to be an /// optimistic concurrency token. /// /// </summary> /// /// <returns> /// The same <see cref="T:System.Data.Entity.ModelConfiguration.Configuration.ConventionPrimitivePropertyConfiguration"/> instance so that multiple calls can be chained. /// /// </returns> /// /// <remarks> /// Calling this will have no effect once it has been configured. /// This method throws if the property is not a <see cref="T:Byte[]"/>. /// /// </remarks> public virtual ConventionPrimitivePropertyConfiguration IsRowVersion() { if (this._configuration() != null) { if (this._binaryConfiguration.Value == null) throw new InvalidOperationException(Strings.LightweightPrimitivePropertyConfiguration_IsRowVersionNonBinary((object) this._propertyInfo.Name)); if (!this._binaryConfiguration.Value.IsRowVersion.HasValue) this._binaryConfiguration.Value.IsRowVersion = new bool?(true); } return this; }
The comment says "The actual data type will vary depending on the database provider being used.".
So without further investigation I assume that the SQLite provider does not play well with the "IsRowVersion " configuration.
Additional what we can do is to remove the Convention in the SQLiteContextInitializert. This means the "Timestamp" attribute will just be ignored.
from sqlitecodefirst.
from sqlitecodefirst.
Related Issues (20)
- Update to new csproj-Format
- Can I use SqliteCreateDatabaseIfNotExists within an external transaction? HOT 6
- Create, Drop and Recreate the same database HOT 5
- Nuget package for .net Core HOT 14
- Feature Request: Drop database if seed values change HOT 6
- [DatabaseGenerated(DatabaseGeneratedOption.Identity)] for Guid HOT 2
- CASCADE verbs HOT 5
- Why need EntityFramework.SqlServer.dll? HOT 1
- EF6.4, CodeFirst 1.6, no such a table HOT 4
- Question - What are the steps required? HOT 2
- SetInitializer Instance Reference issue HOT 2
- Project Status and Release Schedule
- Create index HOT 1
- Autoincrement Fail With Key multiple HOT 4
- Feature request: Support for setting a default collation HOT 5
- Can't find by guid in iqueryable collection HOT 1
- [document enhancement] compare with Microsoft.EntityFrameworkCore.Sqlite? HOT 3
- add .NET Standard 2.0 target HOT 3
- Migration tries to create existing table HOT 17
- Always create missing tables? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlitecodefirst.