【发布时间】:2018-08-30 11:18:51
【问题描述】:
我使用 Entity Framework 6,代码优先。
我有一个由我无权访问的框架 (Azure Mobile Server SDK) 创建的列 <string> Id。
public abstract class EntityData
{
[Key]
[TableColumn(TableColumnType.Id)]
public string Id { get; set; }
...
}
如果我不执行任何操作,则此类列将在 SQL Server 中映射为 nvarchar(MAX)。
我已经能够使用 Fluent API 中的这个 sn-p 将其变成 char(36):
PropertyConventionConfiguration pkConf = modelBuilder.Properties<string>().Where(p => p.Name == "Id");
pkConf.Configure(p => p.IsUnicode(false));
pkConf.Configure(p => p.HasMaxLength(36));
pkConf.Configure(p => p.IsFixedLength());
我想设置为uniqueidentifier。
如何使用类似的 Fluent API 代码 sn-p 做到这一点?
非常感谢!
【问题讨论】:
-
如果将 Id 更改为 Guid 类型而不是字符串会发生什么?您显然需要删除长度限制。 Guid 应该映射到唯一标识符。
-
我无法触及类定义,因为它在 Azure SDK 中,而不是我的代码中
-
在下面发布响应作为答案。
-
这解决了您的问题吗?
-
@MehdiIbrahim 请检查我的 cmets 你的答案
标签: entity-framework-6 azure-mobile-services uniqueidentifier ef-fluent-api ef-code-first-mapping