c# - System.Data.Linq.Mapping 和 System.ComponentModel.DataAnnotations.Schema 中的 TableAttribute 类之间的差异

标签 c# linq entity-framework

我正在使用 EF 6.1,试图运行一个简单的示例代码。
我不小心使用了命名空间System.Data.Linq.Mapping(VS Intellisense)来实现TableAttribute名称参数没有效果,代码在执行时创建了一个新表(因为POCO类名与表名不同)。然而,预计将使用现有的表。 后来经过几次谷歌搜索后,我注意到命名空间 System.ComponentModel.DataAnnotation 在某些地方使用。当我进行此更改时,我的示例开始使用现有表而不是创建它。 我想知道

  • 这两个命名空间中的TableAttribute类有什么区别?

  • 为什么 System.Data.Linq.Mapping 中的 TableAttribute 没有产生预期的行为?

最佳答案

  • System.Data.Linq.Mapping.TableAttribute 属于 LINQ to Entities。
  • Entity Framework 使用System.ComponentModel.DataAnnotation.TableAttribute

关于c# - System.Data.Linq.Mapping 和 System.ComponentModel.DataAnnotations.Schema 中的 TableAttribute 类之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22508063/

相关文章:

c# - 多上下文内存数据库

C# Windows 窗体被任务管理器杀死......有没有办法运行关机功能?

c# - System.DirectoryServices.ActiveDirectory 和 Microsoft.ActiveDirectory 之间的区别

c# - 无法将 'System.Int16' 类型的对象转换为 'System.String' 类型

c# - 检查linq中的最后一项

c# - “可为空的对象必须有一个值。”对于 LINQ c# 中的列表

c# - Entity Framework LINQ To Entities 生成奇怪的慢 SQL Where-Clause

c# - 在 asp net core 控制台应用程序中读取 appsettings

c# - 将基于回调的异步方法转换为可等待任务的最佳方法

c# - Linq to Sql 以 lambda 和作为 where 条件