gpt4 book ai didi

c# - Entity Framework 指南

转载 作者:可可西里 更新时间:2023-11-01 09:03:49 25 4
gpt4 key购买 nike

我正在尝试使用 SQL Server 2008 设置 Entity Framework 。我将 Guid 用于表上的键。有没有办法设置它以便数据库自动生成 key ?我尝试将“RowGuid”设置为 true,并将列的默认值设置为“(newid())”。无论哪种方式,映射类仍然需要我在 C# 端给它一个 Guid。有什么想法吗?

最佳答案

Not yet :

17.4.Can I use a server-generated guid as my entity key?

Unfortunately, in v1 of the EF this is not supported. While it is possible with SQL Server to have a column of type “uniqueidentifier” and to set it’s default value to be “newid()”, with SQL Server 2000 there’s no good way to extract the value that the server generated at the time you do the insert. This can be done on more recent versions of SQL Server, though, so the intent is that we should find a clean way to special case this support in future versions of the EF so it can be supported on those databases that allow it and not on others. For now, the work around is to generate the guid on the client (ideally in the constructor of your object) rather than on the server.

关于c# - Entity Framework 指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/332273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com