gpt4 book ai didi

c# - 如何将 POCO 类与数据库进行比较?

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:01 27 4
gpt4 key购买 nike

我需要将我的 POCO 类中的内容与我的数据库进行比较。我目前正在使用 Microsoft RoslynMicrosoft.SqlServer.SMO 并在我看来“大致”比较数据。它运行完美,但我想知道是否有更好的方法。

今天我必须使用 Roslyn 编译文件,加载数据库信息并比较我想要的内容。

假设我有这个 POCO 文件:

[Table("XPTO", Schema="ASD")]
public class MyPoco
{
public int PropId {get; set;}
public virtual Prop Prop {get; set;}
public DateTime? MyDate {get; set;}
}

而且我还有表格信息。我想看看我的 POCO 类 (MyDate) 中可以为 null 的内容在我的数据库中是否可以为 null,反之亦然。我想看看我的数据库是否有一个 Foreign Key 来表 Props 以及它是否像我的 POCO 中那样不可为空。

正如我所说,它今天已经可以工作了,我只是想重写代码以使用更有效的方式进行维护。

EntityFramework 是否提供某种 API 或其他任何东西?

系统信息

SQL Server 2008 R2
Entity Framework 4.1
C# 4.0

谢谢();

最佳答案

如果我没看错您的问题 - 您需要一些 API 从 DbContext 中获取 relationshiops 和其他 metadata 信息还是 EF/code-first 在运行时?

到目前为止我见过的最好的 - 也是我们两个人能做的最好的是......

How I can read EF DbContext metadata programmatically?

...看看这是否可以帮助您...

And you're welcome to post there if you happen to come into possession of some new and vital piece of information (we made it with the intention to serve as a one-stop question for subjects like this).

关于c# - 如何将 POCO 类与数据库进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15812128/

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