I updated to the latest version of Devart Entity Developer 6.3.569 today and the associated Salesforce .net connector. Now I am getting messages like this
The 'ForeclosureShortsaleDate' property on 'Account' could not be set to a 'null' value. You must set this property to a non-null value of type 'System.DateTime'.
This is happening when I am pulling a record from the context. I have removed many fields from the model that have generated this error because I don't need them anyway but this is not ideal. Especially of the model needs to be recreated, Can anyone explain this to me? All of the columns in question have the Nullable property set to true.
Additional Info:
Template: DBContext
I can't say that the updated version is the issue because I don't know what the Salesforce team are doing in the Sandbox but this context worked properly last week by pulling and pushing data into the sandbox. Up until till this point there have been no model changes on my end. Any help would be appreciated.
UPDATE:
I created a clean and fresh model and I get the same results.
UPDATE:
I believe it is indeed Devart Entity Developer. I checked the last version in version control and this is what the property looked like before version 6.3.569
/// <summary>
/// There are no comments for BillingLatitude in the schema.
/// </summary>
public virtual global::System.Nullable<double> BillingLatitude
{
get;
set;
}
and what it looks like with 6.3.569
/// <summary>
/// There are no comments for BillingLatitude in the schema.
/// </summary>
public virtual global::System.Double BillingLatitude
{
get;
set;
}
I'm going to revert to the last version and generate the model again.
The problem is version 6.3.569 of Entity Developer. The Model Generation is not working properly.
this is the results from 6.3.555
/// <summary>
/// There are no comments for BillingLatitude in the schema.
/// </summary>
public virtual global::System.Nullable<double> BillingLatitude
{
get;
set;
}
Related
I've created a code-fist model for entity framework core. I did an add-migration and noticed somethings weren't correct. So, I removed the migration, made my changes and tried again. After several cycles of add/remove/add/remove... I was seeing things not change.
Here the model I'm having problems with:
namespace CompetenciesDataModel {
/// <summary>
/// This entity represents the different Competencies that an employee may have, plus a comptency may have
/// have skills that are shared across competencies.
/// This entity is a look up table that can only be modifed by an administrator.
/// </summary>
public class Competency {
/// <summary>
/// The primary key for the competencies
/// </summary>
[DatabaseGenerated( DatabaseGeneratedOption.Identity )]
public Guid CompetencyId { get; set; }
/// <summary>
/// The name of the competency
/// </summary>
[Required]
public string CompetencyName { get; set; }
/// <summary>
/// The list of skills that are part of this competency
/// </summary>
public List< CompetencySkillAssoc > CompetenciesAndSkills { get; set; }
}
Notice there are three items. When I do the add-migration, the scaffolding code shows three items, except the third one is called Competencies and not CompetenciesAndSkills. It is of type Guid and then is setup as an index on a column that I didn't create. When I look at the other indexes being created they are being done on the primary key. I've even stated that the CompetencyId is a Key and I still get the same result.
The CompetenciesAndSkills is an association table for a many-to-many relationship with a different table.
There isn't any tables within the DB since it doesn't exist, is there anywhere there's a cache that I'm missing to clear? Or, am I just not understanding something else?
Thanks in advance
The Competency entity is used as a lookup table. Therefore, when I attempted to have the Competency entity as part of a different entity (call it EntityX), the migration created a Foriegn Key within the Competency entity. After realizing that this was a look up and wasn't going to change much (unless some product adminstrator edited).
EntityX had a one-to-many relationship with Competency. Therefore, I created a new entity that contained a key to EntityX and the Competency entity. When I did the migration I didn't have an extra column being made that contained the foriegn key back to EntityX.
I have a model like
public class MyEntity
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Required]
public int Id { get; set; } // Id
[Required]
[Key]
public System.Guid GUID { get; set; }
}
The GUID property is the PK by design, but I have a db generated Id property that I use within my code to determine if the object is a new object that hasn't been saved yet.
When I save this object with Entity Framework, the Id property does not get back populated as normally happens for database generated properties (although usually these are keys). I have to query the DB for the object and grab the ID manually. It seems EF only back populates Key properties on SaveChanges.
Is there any way to get EF to automatically populate the Id property here? Setting it as the Key is not an option, I have dozens of tables that are FK'd to the GUID property and for good reason.
EDIT: I have discovered that the package https://entityframework-extensions.net/ is handling my save changes. If I use the standard EF savechanges it works, but not with the extensions version.
Disclaimer: I'm the owner of Entity Framework Extensions
It was indeed an issue in our library. This scenario was not yet supported for EF6.
However, starting from the v4.0.50, it should now work as expected.
I am using Entity Framework 6 with PostgreSQL.
I have an entity in which I want to prevent concurrency issues, following this documentation I added a RowVersion property with [Timestamp] attribute, however after saving changes to the entity the column RowVersion value stays the same in the database.
[Timestamp]
public byte[] RowVersion { get; set; }
Am I missing something or is there another way to handle it in PostgreSQL?
Just an updated answer for EF Core in case anyone else wanders here.
The Npgsql framework has built-in support for this using the hidden system column xmin that the OP is using in his entity as a NotMapped property.
As referenced here, you can set the xmin column as a concurrency token within EF by calling the UseXminAsConcurrencyToken method on your entity within its OnModelCreating method via Fluent API (a Data Annotation is not available at this time as far as I'm aware).
For anyone already using Fluent API configurations, it's as simple as this:
public class AwesomeEntityConfiguration : IEntityTypeConfiguration<AwesomeEntity>
{
public void Configure(EntityTypeBuilder<AwesomeEntity> builder)
{
builder.UseXminAsConcurrencyToken();
}
}
/// <summary>
/// Meant to validate concurrency en database update
/// This column is updates itself in database and only works in postgresql
/// </summary>
[ConcurrencyCheck]
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
//[NotMapped]
public string xmin { get; set; }
Had to add [NotMapped] attribute just for the column not to be added in the migration, commented it after database-update.
I'm using Entity Framework code-first mode, but how to auto-generate class field comments to database?
Example:
[Table("User")]
public class User
{
/// <summary>
/// Id
/// </summary>
public long Id{get;set;}
/// <summary>
/// this is name
/// </summary>
public string name{get;set;}
}
SQL should be like this:
CREATE TABLE User
(
id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT 'Id',
name VARCHAR(128) NOT NULL COMMENT 'this is name'
)
Does anyone have an idea how to achieve this?
To give a more specific answer besides "not." in the comments.
It's basically not possible to achieve this as comments are not passed over to the compiled object that is taken as the base for generating the migration elements.
In addition consider that the free comment section might contain a comment that might be used as a book (i.e. there's no limitation on comments but there is on comments in the database).
You might consider using a new attribute that might suit your needs, like:
[DbComment('This field is containing bla bla')]
public int FooBar {get; set;}
This might then be incorporated into the database generation process by overwriting the Sql-Generation classes.
The concern by using this approach is still that comments need to be maintained twice.
I'm starting new project and I'd like to use HierarchyID in my DB model and CodeFirst approach. So I added EntityFramework.HierarchyId using nuget.
But when I run Update-Database, I receive this exception:
Schema specified is not valid. Errors:
(0,0) : error 0040: The Type hierarchyid is not qualified with a namespace or alias. Only primitive types can be used without qualification.
This is how my table looks like:
public class Activity
{
[Key]
public int ActivityId { get; set; }
public HierarchyId ActivityPath { get; set; }
public string Name { get; set; }
}
I know that I had to miss samething easy, but I'm not able to find useful sample on Google. Thank you!
I finally found a reason of this issue.
Because the whole solution is new, it was using ./express database (I don't know why it chose exactly this instance... maybe it's default). And even if I have installed MS SQL 2012, instance of ./express is SQL2005 -> no hierarchyId support. When I specified connection string explicitly to newer version, problem solved.
I'll keep this post to help others... Don't forget to vote up if you are one of them.