Question

Yesterday i asked this question: Generating a SQL view from EF 6.1 code first

And i thought that everything was working fine, though i still have some troubles when generating a new migration. When i generate a new one, EF sees some changes or irregularities in the views that it wants to changes. But, as far as i know a view's columns c.q. primary key aren't changable?

 DropPrimaryKey("dbo.myView1");
 DropPrimaryKey("dbo.myView2");
 AlterColumn("dbo.myView1", "Name", c => c.String(maxLength: 255, unicode: false));
 AlterColumn("dbo.myView1", "SecondName", c => c.String(maxLength: 255, unicode: false));
 AlterColumn("dbo.myView1", "MultipleNames", c => c.String(maxLength: 255, unicode: false));
 AlterColumn("dbo.myView2", "Price", c => c.Decimal(nullable: false, precision: 18, scale: 2));
 AlterColumn("dbo.myView2", "TypeName", c => c.String(maxLength: 255, unicode: false));
 AddPrimaryKey("dbo.myView1", "Id");
 AddPrimaryKey("dbo.myView2", "Id");

Does someone knows a solution for this?

I thought at first that the MyView1.Name field wasn't equal to the view field. But in the database the field is a normal: varchar(255) not null en in my code it's a string with a max length of (255).

So i don't see how to avoid this generation? Any ideas?

EDIT:

The only one i do understand is the MyView2.Price field, which is a decimal(standard 18,2) in my code. and a decimal(19,4) in the database. So that can be fixed while changing my model. but the strings?? still no idea..

Was it helpful?

Solution

SOLVED: Solving the Decimal issue will automatically resolve all the other issues.

It seems that the id's are dropped and created to make it possible to do renaming? And to prevent errors.

Still i'm not sure though.. Why the string issue where created..

Note: as you can see from the previous post, i generated my models from an exisiting database. Before doing adding any new migration, be sure to remove all [Key] attributes in the model of your SQL view. This seems to be part of the solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top