Entity framework 微风“;属性是必需的;EF 6.1.3当无所需属性时
从EF 6.1.1更新到6.1.3后,breeze开始在我的一个属性上执行此操作 以下是对象结构:Entity framework 微风“;属性是必需的;EF 6.1.3当无所需属性时,entity-framework,breeze,Entity Framework,Breeze,从EF 6.1.1更新到6.1.3后,breeze开始在我的一个属性上执行此操作 以下是对象结构: public class Class1 { public virtual string myProperty { get; set; } // other properties } public class Class2 : Class1 { // other properties } public class Class3 : Class1 { [Requ
public class Class1
{
public virtual string myProperty { get; set; }
// other properties
}
public class Class2 : Class1
{
// other properties
}
public class Class3 : Class1
{
[Required]
public override string myProperty { get; set; }
// other properties
}
我正在breeze中创建一个“Class2”对象并试图保存它。我没有在任何地方设置“myProperty”,因为在这个页面上不需要它,所以根本没有链接到它的输入。当我保存更改时,会收到一条消息说“myProperty是必需的”
回到EF 6.1.1,一切正常,但我运行该更新用于其他目的
编辑:我看到在更新到6.1.3之后,属性的“Class1”元数据中有一个null:false。我可以很容易地假设问题存在,但是为什么会产生这个问题以及如何避免它,字符串在技术上默认为空。首先,它不依赖于Breeze EF 6.1.3
这正是你写的东西,对我来说是EF上的一个BUG。
我使用这个模型/上下文/测试来重现错误
public class Class1
{
[Key]
public int Id { get; set; }
public virtual string MyProperty { get; set; }
// other properties
}
public class Class3 : Class1
{
[Required]
public override string MyProperty { get; set; }
public string Class3Prop { get; set; }
}
public class TestContext : DbContext
{
public TestContext(DbConnection connection) : base(connection, true) { }
public DbSet<Class1> C1s { get; set; }
public DbSet<Class3> C3s { get; set; }
}
public static void Run(DbConnection connection)
{
using (TestContext db = new TestContext(connection))
{
// MyProperty not specified
db.C1s.Add(new Class1());
db.SaveChanges(); // Here in EF 6.1.3 is raised an exception because MyProperty is required but we did not mark it as Required
}
}
公共类1
{
[关键]
公共int Id{get;set;}
公共虚拟字符串MyProperty{get;set;}
//其他属性
}
公开课三级:一级
{
[必需]
公共重写字符串MyProperty{get;set;}
公共字符串Class3Prop{get;set;}
}
公共类TestContext:DbContext
{
publictestcontext(DbConnection-connection):base(connection,true){}
公共数据库集C1s{get;set;}
公共DbSet C3s{get;set;}
}
公共静态无效运行(DbConnection)
{
使用(TestContext db=newTestContext(连接))
{
//未指定MyProperty
db.C1s.Add(new Class1());
db.SaveChanges();//这里在EF 6.1.3中引发了一个异常,因为MyProperty是必需的,但我们没有将其标记为必需的
}
}
数据库只包含1个表(当然还有_MigrationHistory)
Class1(Id自动递增、MyProperty varchar not null、Class3Prop varchar null、鉴别器varchar not null)
因此,我们将永远无法插入空MyProperty
EF 6.1.1一切正常。
添加C1有效,添加C3(不设置MyProperty)无效 数据库包含与上面相同的表,但MyProperty可为空 关于6.1.3的其他考虑事项 通过流畅的界面进行配置,行为不会改变。
此外,如果在Class1中指定MaxLength 30,在Class3中指定15,则字段将为varchar 15。
对我来说,这绝对是一个EF 6.1.3错误(我在CodePlex上发布过)首先,它不依赖于Breeze EF 6.1.3
这正是你写的东西,对我来说是EF上的一个BUG。
我使用这个模型/上下文/测试来重现错误
public class Class1
{
[Key]
public int Id { get; set; }
public virtual string MyProperty { get; set; }
// other properties
}
public class Class3 : Class1
{
[Required]
public override string MyProperty { get; set; }
public string Class3Prop { get; set; }
}
public class TestContext : DbContext
{
public TestContext(DbConnection connection) : base(connection, true) { }
public DbSet<Class1> C1s { get; set; }
public DbSet<Class3> C3s { get; set; }
}
public static void Run(DbConnection connection)
{
using (TestContext db = new TestContext(connection))
{
// MyProperty not specified
db.C1s.Add(new Class1());
db.SaveChanges(); // Here in EF 6.1.3 is raised an exception because MyProperty is required but we did not mark it as Required
}
}
公共类1
{
[关键]
公共int Id{get;set;}
公共虚拟字符串MyProperty{get;set;}
//其他属性
}
公开课三级:一级
{
[必需]
公共重写字符串MyProperty{get;set;}
公共字符串Class3Prop{get;set;}
}
公共类TestContext:DbContext
{
publictestcontext(DbConnection-connection):base(connection,true){}
公共数据库集C1s{get;set;}
公共DbSet C3s{get;set;}
}
公共静态无效运行(DbConnection)
{
使用(TestContext db=newTestContext(连接))
{
//未指定MyProperty
db.C1s.Add(new Class1());
db.SaveChanges();//这里在EF 6.1.3中引发了一个异常,因为MyProperty是必需的,但我们没有将其标记为必需的
}
}
数据库只包含1个表(当然还有_MigrationHistory)
Class1(Id自动递增、MyProperty varchar not null、Class3Prop varchar null、鉴别器varchar not null)
因此,我们将永远无法插入空MyProperty
EF 6.1.1一切正常。
添加C1有效,添加C3(不设置MyProperty)无效 数据库包含与上面相同的表,但MyProperty可为空 关于6.1.3的其他考虑事项 通过流畅的界面进行配置,行为不会改变。
此外,如果在Class1中指定MaxLength 30,在Class3中指定15,则字段将为varchar 15。
对我来说,这绝对是一个EF 6.1.3错误(我在CodePlex上发布过)我没有回答你的问题。您可以尝试通过fluent界面进行配置(我做了一些其他测试,然后我会做)。我没有回答您的问题。您可以尝试通过fluent界面进行配置(我做了一些其他测试,然后我会做)