How set MergeOption in ObjectQuery in SharpRepository for query?

23 views
Skip to first unread message

evgenyk...@gmail.com

unread,
Jul 18, 2016, 11:00:31 AM7/18/16
to SharpRepository
How set MergeOption in ObjectQuery in SharpRepository for query?
In EF example:

using (var context = new MyDbContext(),
// Get ObjectContext from DBContext
objectContext = ((IObjectContextAdapter)context).ObjectContext) {

// Construct an ObjectQuery
var customers = objectContext.CreateObjectSet<Customer>()
.Where(c => c.State == "VA").Take(2));

// Set the MergeOption property
(customers as ObjectQuery<Customer>).MergeOption =
MergeOption.OverwriteChanges;

// Do something with your data
foreach(var customer in customers) { ... }
}

Jeff Treuting

unread,
Jul 18, 2016, 12:28:48 PM7/18/16
to evgenyk...@gmail.com, SharpRepository

Since that is a specific EF feature, there is not a built-in option for doing it via a flag or parameter.  The only way I can think of is to create a custom aspect for implementing that behavior.


There are some example blog posts on this page that give examples of where you can hook in via writing custom attributes. 


Hope this helps.


https://github.com/SharpRepository/SharpRepository/wiki/Hooks


From: sharpre...@googlegroups.com <sharpre...@googlegroups.com> on behalf of evgenyk...@gmail.com <evgenyk...@gmail.com>
Sent: Monday, July 18, 2016 8:00:31 AM
To: SharpRepository
Subject: [SharpRepository] How set MergeOption in ObjectQuery in SharpRepository for query?
 
--
You received this message because you are subscribed to the Google Groups "SharpRepository" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharpreposito...@googlegroups.com.
To post to this group, send email to sharpre...@googlegroups.com.
Visit this group at https://groups.google.com/group/sharprepository.
To view this discussion on the web visit https://groups.google.com/d/msgid/sharprepository/038d8223-ce3a-4097-a65b-9d270ab4c80f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages