询问者
Entity Framework 设置了最大长度 超出时怎么自动截取??急急急

问题
全部回复
-
HasMaxLength限制了最大允许容量只能是256(nvarchar)个字符。因此我建议你设法用js在UI端判断输入字符长度是否超过256个。
或者在保存的时候:
xxEntityName.someProperty = xxEntityName.someProperty.ToString().SubString(0,256);
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
我希望能够自动截取可以么??
恐怕不行。If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
你好,
你可以尝试这样的方法:
this.Property(p => (p.Name.ToString().Length > 256 ? p.Name.ToString().Substring(0, 256) : p.Name)).IsRequired().HasColumnType("varchar").HasMaxLength(256);
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已建议为答案 Happy Chen - MSFTModerator 2013年9月9日 1:15