2016-03-03 24 views

回答

1

不幸的是,我認爲這個問題的答案是,你不能。

在FluentAPI你可以使用,這將在整個環境中應用定製的約定:

//All strings are required 
modelBuilder.Properties<string>() 
    .Configure(p => p.IsRequired()); 

//All strings named "Foo" are required and have a maximum length 
modelBuilder.Properties<string>() 
    .Where(p => p.Name == "Foo") 
    .Configure(p => p.IsRequired().HasMaxLength(256)); 

//All strings with a "Required" attribute have a maximum length: 
modelBuilder.Properties<string>() 
    .Where(p => p.CustomAttributes 
       .Where(a => a.AttributeType == typeof(RequiredAttribute)) 
       .Any()) 
    .Configure(p => p.HasMaxLength(256)); 

的問題是,流利的API並沒有給進入一個「AllowEmptyStrings」屬性。它可能是爲了配置數據庫而設計的。並檢查空字符串是之前的數據獲取到數據庫

參考,通常會進行驗證:Custom Conventions

+0

THX。我無法找到任何迭代可用的modelBuilder API的任何東西。 – Dave

相關問題