--
You received this message because you are subscribed to the Google Groups "NoRM mongodb" group.
To post to this group, send email to norm-m...@googlegroups.com.
To unsubscribe from this group, send email to norm-mongodb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/norm-mongodb?hl=en.
Save is a "smart" wrapper around Update and Insert...so it'll try to
figure out whether you want to save or insert, and for an update,
it'll generate the proper query to update just that instance.
On Apr 3, 4:50 pm, Howard van Rooijen <howard.vanrooi...@gmail.com>
wrote:
> Excellent - thanks for that - I ended up making a small adjustment - I
> created a new interface:
>
> public interface IUniqueIdentifier
> {
> ObjectId Id { get; set; }
>
> }
>
> and then ensured that my POCO implemented it then I could implement your
> workaround in the original session object:
>
> public void Update<T>(T item) where T : class, IUniqueIdentifier, new()
> {
> this.provider.DB.GetCollection<T>().UpdateOne(new { _id = item.Id },
> item);
>
> }
>
> and this now displays the correct behaviour.
>
> Many thanks,
>
> Howard
>
> >> norm-mongodb...@googlegroups.com<norm-mongodb%2Bunsu...@googlegroups.com>
The session's Update() method "don't work" for me too. To use the
following code :
session.Update(originalContact, contactToEdit);
I had to add another Update method :
public void Update<T>(T match, T value) where T : class, new()
{
_provider.DB.GetCollection<T>().UpdateOne(match, value);
}
You must pass the original object and the updated object to the Update
method so that the update work properly.
Michel
I ran into the same problem. Update had no effect. I was using the
model in the test project
public void Update<T>(T entity) where T : class, new()
{
provider.DB.GetCollection<T>().UpdateOne( entity, entity );
}
Then your hints above got it working for me:
public void Update<T>(T entity) where T : IHasIdentifier, new()
{
provider.DB.GetCollection<T>().UpdateOne( new {_id = entity._id},
entity );
}
where IHasIdentifier is defined as:
interface IHasIdentifier
{
ObjectId _id {get; set;}
}
The benefit of defining the property like that (rather than say ID) is
when you insert it, the entity automatically get's its mongo generated
ID set. Then using "new {_id = entity._id}" as the match criteria
seemed to work fine.
Hope this helps someone out there.
Best regards,
Michael
Michael Kennedy
http://www.michaelckennedy.net
@mkennedy
On Apr 6, 8:12 am, Michel <mich...@gmail.com> wrote:
> Bonjour,
>
> The session'sUpdate() method "don't work" for me too. To use the
> following code :
>
> session.Update(originalContact, contactToEdit);
>
> I had to add anotherUpdatemethod :
>
> public voidUpdate<T>(T match, T value) where T : class, new()