在Entity Framework 4.1 Code First中手动生成主键的最佳方法是什么?
我正在编写ASP.NET MVC 3并使用存储库模式.
我目前使用以下代码按顺序生成密钥:
'Code First Class
Public Class Foo
<Key()>
<DatabaseGenerated(DatabaseGeneratedOption.None)>
Public Property iId As Integer
Public Property sBar As String
End Class
'Context Class
Public Class FooBarContext : Inherits DbContext
Public Property Foos As DbSet(Of Foo)
End Class
'Get the current Id
'Part of code in repository that stores Entity Foo.
Dim iCurrId as Integer = (From io In context.Foo
Select io.iId()).Max
Dim iNewId as Integer = iCurrId + 1
Foo.iId = iNewId …Run Code Online (Sandbox Code Playgroud) 我有最新版本的VS 2010,.NET 4.0和MVC 3,使用vb.net时我在使用asp.net mvc 3中的区域时遇到问题.
我做以下事情:
在步骤7,我收到消息"无法找到资源".
如果我使用c#执行完全相同的操作,那么我将进入正确的页面,它将按预期显示"Index"一词.
这是一个错误,还是我错过了什么?我一直在扫描网络几个小时试图解决这个问题,但我现在正在接受.
这是自动创建的TestAreaRegistration.vb文件命名空间TestApp.Areas.Test公共类TestAreaRegistration继承AreaRegistration
Public Overrides ReadOnly Property AreaName() As String
Get
Return "Test"
End Get
End Property
Public Overrides Sub RegisterArea(ByVal context As System.Web.Mvc.AreaRegistrationContext)
context.MapRoute( _
"Test_default", _
"Test/{controller}/{action}/{id}", _
New With {.action = "Index", .id = UrlParameter.Optional} _
)
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)
结束命名空间
这是自动创建的Global.ascx文件:'注意:有关启用IIS6或IIS7经典模式的说明,请访问http://go.microsoft.com/?LinkId=9394802
公共类MvcApplication继承System.Web.HttpApplication
Shared Sub RegisterGlobalFilters(ByVal filters As …Run Code Online (Sandbox Code Playgroud)