草庐IT

c# - 为什么 EF 返回代理类而不是实际实体?

当我想要实际的实体类时,我遇到了EntityFramework返回代理的问题。第一次运行我的代码时,一切都正常运行(没有代理),但之后的每次迭代中,我的一个DbSet总是返回代理而不是实际类型。我在每次迭代后处理上下文,所以我不明白为什么第一次通过它有效,而之后每次都无效。我的代码在此行失败。我所有的POCO都设置了Table属性,但是因为它返回一个代理类,所以没有table属性。TableAttributeattrib=(TableAttribute)attributes.Single();在我销毁对象后,DbContext中是否存在一些幕后静态魔法?我使用以下方法将我的对象移动到内

c# - 为什么 EF 返回代理类而不是实际实体?

当我想要实际的实体类时,我遇到了EntityFramework返回代理的问题。第一次运行我的代码时,一切都正常运行(没有代理),但之后的每次迭代中,我的一个DbSet总是返回代理而不是实际类型。我在每次迭代后处理上下文,所以我不明白为什么第一次通过它有效,而之后每次都无效。我的代码在此行失败。我所有的POCO都设置了Table属性,但是因为它返回一个代理类,所以没有table属性。TableAttributeattrib=(TableAttribute)attributes.Single();在我销毁对象后,DbContext中是否存在一些幕后静态魔法?我使用以下方法将我的对象移动到内

c# - ef core 在更新数据库期间不使用 ASPNETCORE_ENVIRONMENT

我使用visualstudio通过特定的迁移来更新我的所有环境。使用下面的命令它运行良好。update-database-MigrationinitMigrationProduct-cProductContext-EnvironmentProduction在efcore2.0中,此命令已更改,参数-Environment已删除。它在文档中说。"With2.0,youcanusetheASPNETCORE_ENVIRONMENTenvironmentvariableinstead."https://learn.microsoft.com/en-us/ef/core/miscellaneo

c# - ef core 在更新数据库期间不使用 ASPNETCORE_ENVIRONMENT

我使用visualstudio通过特定的迁移来更新我的所有环境。使用下面的命令它运行良好。update-database-MigrationinitMigrationProduct-cProductContext-EnvironmentProduction在efcore2.0中,此命令已更改,参数-Environment已删除。它在文档中说。"With2.0,youcanusetheASPNETCORE_ENVIRONMENTenvironmentvariableinstead."https://learn.microsoft.com/en-us/ef/core/miscellaneo

c# - Entity Framework EF.Functions.Like 与 string.Contains

我正在阅读EntityFramework核心2.0的公告https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-entity-framework-core-2-0/它说他们添加了新的Sql函数,例如EF.Functions.Like来执行SQLLIKE操作。我想知道,EF.Functions.Like和string.Contains/StartsWith之间的区别是什么?例如:varcustomers=context.Customers.Where(c=>c.Name.StartsWith("a"));//Versio

c# - Entity Framework EF.Functions.Like 与 string.Contains

我正在阅读EntityFramework核心2.0的公告https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-entity-framework-core-2-0/它说他们添加了新的Sql函数,例如EF.Functions.Like来执行SQLLIKE操作。我想知道,EF.Functions.Like和string.Contains/StartsWith之间的区别是什么?例如:varcustomers=context.Customers.Where(c=>c.Name.StartsWith("a"));//Versio

c# - EF5 收到此错误消息 : Model compatibility cannot be checked because the database does not contain model metadata

我每次运行应用程序时都会不断显示此错误消息。我正在使用实体Framework5:CodeFirst这是错误信息,System.NotSupportedException:Modelcompatibilitycannotbecheckedbecausethedatabasedoesnotcontainmodelmetadata.ModelcompatibilitycanonlybecheckedfordatabasescreatedusingCodeFirstorCodeFirstMigrations.atSystem.Data.Entity.Internal.ModelCompatib

c# - EF5 收到此错误消息 : Model compatibility cannot be checked because the database does not contain model metadata

我每次运行应用程序时都会不断显示此错误消息。我正在使用实体Framework5:CodeFirst这是错误信息,System.NotSupportedException:Modelcompatibilitycannotbecheckedbecausethedatabasedoesnotcontainmodelmetadata.ModelcompatibilitycanonlybecheckedfordatabasescreatedusingCodeFirstorCodeFirstMigrations.atSystem.Data.Entity.Internal.ModelCompatib

c# - EF 异常 : String or binary data would be truncated. 语句已终止。?

我已经阅读了很多与此问题相关的帖子,但找不到答案。我正在尝试将大量数据从Excel加载到SQLServer中。数以千计的记录。我得到了这个异常(exception):Stringorbinarydatawouldbetruncated.Thestatementhasbeenterminated.显然有些值超过了数据库中的字段大小。错误来自SQLServerAFIK。我的问题-我怎么可能知道是什么记录和什么字段值导致的​​?EF异常中没有具体细节,除了我提到的那个。感谢任何帮助。有人要代码片段,其实很简单,问题不在代码://employeesisaListcollectionloaded

c# - EF 异常 : String or binary data would be truncated. 语句已终止。?

我已经阅读了很多与此问题相关的帖子,但找不到答案。我正在尝试将大量数据从Excel加载到SQLServer中。数以千计的记录。我得到了这个异常(exception):Stringorbinarydatawouldbetruncated.Thestatementhasbeenterminated.显然有些值超过了数据库中的字段大小。错误来自SQLServerAFIK。我的问题-我怎么可能知道是什么记录和什么字段值导致的​​?EF异常中没有具体细节,除了我提到的那个。感谢任何帮助。有人要代码片段,其实很简单,问题不在代码://employeesisaListcollectionloaded