Here's a reproduction
Using build 2.5.2910
So we store a member in the database the normal way:
await session.StoreAsync(member)
I can then sign in, as that member, when
await session.LoadByUniqueConstraintAsync<Member>(m => m.Email, email)
I then do a batch update of email addresses (the batch only contains that one email address)
for (var batch = 0; (records = allRecords.Skip(batch * BatchSize).Take(BatchSize).ToList()).Any(); batch++)
{
using(var querySession = this.documentStore.OpenSession())
{
var existingMembers = session.Query<Member, Member_ByEmail> ().Where(m => m.Email.In(records.Select(r => r.OldEmailAddress))).ToDictionary(m => m.Email, m => m);
using(var bulkInsertOperation = this.documentStore.BulkInsert(this.systemConfiguration.DatabaseName, new BulkInsertOptions { CheckForUpdates = true }))
{
foreach(var member in records)
{
var existingMemberKey = member.OldEmailAddress;
var existingMemberRecord = existingMembers[existingMemberKey];
existingMemberRecord.Email = member.EmailAddress;
}
}
}
}
When I try and log in again with the new email address, this line:
await session.LoadByUniqueConstraintAsync<Member>(m => m.Email, email)
Returns null....
I've checked the new email being used is the same one in the database. The database shows the new one. I've used the database interface and queried the index for the new email and that works.
I've set the database to use wait for non stale results and also:
store.Conventions.DefaultQueryingConsistency = ConsistencyOptions.AlwaysWaitForNonStaleResultsAsOfLastWrite;
None of these options have worked.
I'm wondering if there is something special I have to do with bulk insert operation in order to get the .NET client to read the indexes for this new email.
I've drilled into the session variable at runtime and found that there is a known missing ids field with this value:
"UniqueConstraints/members/email/Ym1hcmxleTFAbmV3b3JiaXQuY28udWs="
You need to download the Raven plugin Raven.Bundles.UniqueConstraints.dll and add it to the \Plugins\ directory in your Raven installation folder (in my case, D:\RavenDB\Plugins)
You will need to re-insert the records after doing this (I deleted the database and re-seeded).
Related
I first used stripe back in 2015. It was easy, then I figured it out (kind of) in 2018/19. But now I'm trying again on an older project and am completely stuck. I'm using checkout.js because I can no longer figure out managing the card, and I can create a customer, add them to a subscription, and even retrieve the customer id. I can pull back customer details, but I can't figure out how to update their subscritpion - specifically how to cancel it. I've updated the metadata aspect after trying for a while on understanding the API, but it doesn't seem to affect the next invoice. Here is my current approach:
StripeConfiguration.SetApiKey("testkey");
var customers = new CustomerService();
var charges = new ChargeService();
var userId = User.Identity.GetUserId();
var user = db.Users.Single(x => x.Id == userId);
var customer = customers.Get(user.CustomerId);
var sub = customer.Subscriptions.FirstOrDefault();
sub.CancelAtPeriodEnd = true;
Somehow I need to update here??
Then this is back to where I just clear out my user.
user.CustomerId = null;
user.Paid = false;
It's not too pretty right now, but I just don't get this.
Another approach is this:
var service = new SubscriptionService();
var options = new SubscriptionUpdateOptions {
CancelAtPeriodEnd = true,
};
Subscription subscription = service.Update("subid", options);
But I don't understand how this ties to the customer and their customerid.
Do you try deleting the custumer? or is not your objective delete it?
StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";
var service = new CustomerService();
service.Delete("cus_H01wAPhnLalFWf");
In the API ref guide says: Also immediately cancels any active subscriptions on the customer
I am working with Sharepoint Online and CSOM and I need to get the owner of a
specific group.
I tried to load data from ClientContext, and got a exception with the message "unknown error".
Here is the code I tried.
MC.ClientContext context = new SPClient.ClientContext("sit url");
MC.Group group = context.Web.SiteGroups.GetById("group id");
context.Load(group, x => x.Owner);
await context.ExecuteQueryAsync();
What's the correct method to get the information that I needed?
I have solved this problem by a quite strange way.
The code is something like this:
ClientContext context = new SPClient.ClientContext("sit url");
Group group = context.Web.SiteGroups.GetById("group id");
context.Load(group, x => x.Owner.PrincipalType, x => x.Owner.LoginName);
await context.ExecuteQueryAsync();
context.Load(group.Owner);
await context.ExecuteQueryAsync();
I need to call the ExecuteQuery method twice to get the object of owner.
I don't know why. But it works.
You can use GroupCollection.GetByName or GetById to retrieve an existing group and then retrieve the groupowner.
using (var context = new ClientContext("sit url"))
{
context.Credentials = credentials;
var groupOwner = context.Web.SiteGroups.GetByName("GroupName");
ctx.ExecuteQuery();
}
I have a database in the Assets folder of the project and I would try to recover the file of the database, but I get an exception. Can not find the file. What should I change?
SQLiteAsyncConnection mussAll = new SQLiteAsyncConnection("ms-appx:///../Assets/Database1.db", true);
Later I would like to fill a List with objects within the database. is correct to do so?
var queryAll = await mussAll.Table<Musei>().ToListAsync();
List<Musei> listAll = new List<Musei>();
foreach(Musei museiAll in queryAll)
{
listAll.Add(museiAll);
}
var qruppim = listAll.OrderBy(x => x.NomeMuseo).GroupBy(x => x.NomeMuseo.Substring(0, 1));
MuseoDettagli.Source = qruppim;
I created a database with SQLite-net so:
SQLiteAsyncConnection conn = new SQLiteAsyncConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "Database.db"), true);
await conn.CreateTableAsync<Musei>();
Musei musPref;
if (muss.NumeroTel != null && muss.Descrizione!=null && muss.indirizzoEmail!= null && muss.Immagine!= null)
{
musPref = new Musei
{
DidascaliaLista=muss.DidascaliaLista,
NomeMuseo = muss.NomeMuseo,
Luogopreciso = muss.Luogopreciso,
Descrizione = muss.Descrizione,
NumeroTel = muss.NumeroTel,
IndirizzoEmail = muss.IndirizzoEmail,
Immagine= muss.Immagine,
};
}
await conn.InsertAsync(musPref);
In another project I need to recover the database created and insert objects inside a ListView, But I do not know how to proceed ..
try
{
StorageFile data = await ApplicationData.Current.LocalFolder.GetFileAsync("Database.db");
}
catch(Exception)
{
}
And now??
I would like to retrieve the database created above and use it, inserting objects "Musei" that are in it and display it in a ListView
If you want to read from the database you created earlier, you can do the following:
// Get a connection to the database that is in the local folder.
var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Database.db");
var con = new SQLiteAsyncConnection(dbPath, true);
// Get all "Musei" in the database stored in the "Musei" table.
var results = await con.QueryAsync<Musei>("SELECT * FROM Musei");
If you only want the Musei that match a certain field value, for example: you only want to read those in the specific location "Rome", you can do that like this:
var searchLocation = "Rome"; // for example entered by the user in your UI.
// Get only the "Musei" in `searchLocation`.
var results = await con.QueryAsync<Musei>("SELECT * FROM Musei WHERE Luogopreciso ='?'", searchLocation);
An alternative, if you are only querying a single table, is to do it like this, using LINQ:
var query = con.Table<Musei>();
// or, if looking for `searchLocation`:
var query = con.Table<Musei>().Where(m => m.Luogopreciso == "Rome");
you can then get this as a list using:
var result = await query.ToListAsync();
To find out which tables are actually present in your opened database files, you can do this:
var nTables = 0;
System.Diagnostics.Debug.WriteLine("Tables in the database");
foreach (var mapping in con.TableMappings)
{
System.Diagnostics.Debug.WriteLine(mapping.TableName);
nTables++;
}
System.Diagnostics.Debug.WriteLine("{0} tables in total", nTables);
and look at the debug output.
I am performing an insert operation with Entity Framework 5.
My code inserts a new row from a user input and parsed values in another method. The debug operation shows all object attributes have a value before the insert operation is called, the code executes without any exception, and the row is updated in the LocalDb, but content column value is missing or never saved.
Here is my entity framework code:
public async Task<IHttpActionResult> PostFormData()
{
var profile = db.ProfileRepository.dbSet.Where(m => m.profileId == 1).FirstOrDefaultAsync().Result;
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var research = new Research();
research.profile = profile;
string root = HttpContext.Current.Server.MapPath("~/documentSafe");
var provider = new MultipartFormDataStreamProvider(root);
try
{
// Read the form data.
await Request.Content.ReadAsMultipartAsync(provider);
research.title = provider.FormData["title"];
research.researchAbstract = provider.FormData["researchAbstract"];
research.publisher = provider.FormData["publisher"];
var areaList = new List<ResearchArea>();
string areas = provider.FormData["researchArea"];
foreach (var r in areas.Split(','))
{
var area = new ResearchArea()
{
name = r,
departmentId = profile.departmentId
};
areaList.Add(area);
}
research.researchArea = areaList;
research.researchType = new ResearchType()
{
name = provider.FormData["type"]
};
string content = WebUtility.HtmlEncode(parser.convert(provider.FileData[0]));
research.content = content;
using (var context = new AcademicContext())
{
context.Research.Add(research);
await context.SaveChangesAsync();
}
return Ok();
}
catch (System.Exception e)
{
return InternalServerError(e);
}
}
The missing column is a parsed html string encoded using webutility and has an average size of 15,000 characters. I have checked the database column attribute too, and it is set to nvarchar(MAX).
If I insert a sample plain text to the column, the value get saved, but if I pass the encoded html string it does not.
Any suggestions why my column will not be null but still not contain any value.
Solution: The sql server explorer in visual studio seem to display an empty column when the character size is greater than 4000. I ran multiple test to verity this. I could get the content of the empty column by running raw sql select query.