Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DbContext 模式如何手動標記實體已經變更 #1893

Open
sableangle opened this issue Sep 26, 2024 · 1 comment
Open

DbContext 模式如何手動標記實體已經變更 #1893

sableangle opened this issue Sep 26, 2024 · 1 comment

Comments

@sableangle
Copy link

在 EF Core 中,如果

public class Foo
{
    public List<string> contents { get; set;}
}

var foo = dbContext.Foo.First();

foo.contents.Add("some value");
dbContext.SaveChange(); // foo.contents 的異動不會被記錄,因為 EF Core 不會追蹤 IEnumerable 內的成員變動

// 此時會採用這種方式手動標記實體有異動,以令 SaveChange 可以順利保存差異
dbContext.Foo.Entry(foo).State = EntityState.Modified;

爬了一下文件與代碼沒有找到類似的實作,想確認目前的最佳實踐建議為何?
或是 FreeSQL.DbContext 的實作不需要執行類似的手動標記

@2881099
Copy link
Collaborator

2881099 commented Sep 26, 2024

有需要,直接更新更直接。

我们主打的功能,IFreeSql + 仓储。

DbContext 适合过渡使用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants