You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
I am wondering how I would go about updating an child instance in an array?
Here are my models
public class Recording
{
[BsonId]
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public ObjectId Id { get; set; }
//Other Properties
public List<VideoFragment> VideoFragments { get; set; } = new List<VideoFragment>();
}
[ComplexType]
public class VideoFragment
{
public string Url { get; set; }
public byte[] Data { get; set; }
}
Here is my Context
public class MyDbContext : DbContext
{
public StreamcorderDbContext(DbContextOptions options) : base(options)
{ }
public DbSet<Recording> Recordings { get; set; }
}
I am wanting to update an existing Video Fragment by looking it up by Url then saving a byte array of data
Here is what I currently have:
public void SaveFragmentData(ObjectId recordingId, string fragmentUrl, byte[] data)
{
var recording = _db.Recordings.Single(r => r.Id == recordingId);
var fragment = recording.VideoFragments.Single(f=> f.Url == fragmentUrl);
fragment.Data = data;
_db.Recordings.Update(recording);
_db.SaveChanges();
}
I add get the recording, update the specific fragment of the recording then save it.
I was hoping there might be a way to just get the fragment and update it individually.
Currently, the provider only works on top-level Entities, as these are the only values tracked by the change tracker. This means that entire document has to be saved, which is done with a ReplaceOne call.
The change tracker may not recognize deeply nested documents as a "change" since it doesn't track properties of properties (ie: properties of sub-documents). To get around this, you can mark the Entity as updated by calling DbContext.Update<TEntity>(TEntity entity). This will mark the top-level entity as modified, and the next call to DbContext.SaveChanges() will replace the entire document.
The next version of EFCore recently implemented better support for collections of owned entities, which might make this moot. Depending on well it works, I might be able to break up SaveChanges so that it can push and remove array items. I haven't had time to work on that upgrade, or upgrading the provider to support MongoDB 4.0 ACID transactions. I hope to get some time to do both soon.
I am wondering how I would go about updating an child instance in an array?
Here are my models
Here is my Context
I am wanting to update an existing Video Fragment by looking it up by Url then saving a byte array of data
Here is what I currently have:
I add get the recording, update the specific fragment of the recording then save it.
I was hoping there might be a way to just get the fragment and update it individually.
Here is a copy of my document:
Could you help me out?
Ps thanks for creating a provider like this, its super helpful to try out.
The text was updated successfully, but these errors were encountered: