کار با اسناد در RavenDb 4، ثبت و ویرایش
نویسنده: عبدالصالح
تاریخ: ۱۳۹۷/۰۳/۱۵ ۸:۲۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
Public Class User
{
public string Id { get; set; }
public string PhoneNumber { get; set; }
public Dictionary<string, App> Apps { get; set; }
}
public class App
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string UserName { get; set; }
public List<string> Roles { get; set; }
public List<String> Messages { get; set; }
public String AdressId { get; set; }
public bool IsActive { get; set; } = true;
[JsonIgnore]
public string DisplayName => $"{FirstName} {LastName}";
} services.AddSingleton<IDocumentStore>(serviceProvider =>
{
var store = new DocumentStore()
{
Urls = new[] { "http://192.168.1.10:8080" },
Database = "AccountingSystem",
}.Initialize();
return store;
});
services.AddScoped<IAsyncDocumentSession>(serviceProvider =>
{
var store = serviceProvider.GetRequiredService<IDocumentStore>();
return store.OpenAsyncSession();
}); var user = new User
{
PhoneNumber = user.PhoneNumber
};
user.Apps.Add(appCode, new ActiveApp
{
FirstName = "عبدالصالح",
LastName = "کاشانی",
UserName = abdossaleh,
IsActive = true,
RolesId = new List<string>{"Admin"}
});
await _documentSession.StoreAsync(user);
await _documentSession.SaveChangesAsync() var user = await _documentSession.LoadAsync<User>("Users/131-A"); _documentSession.Advanced.Patch<User, string>("Users/131-A",
u => u.PhoneNumber
, "09131110000"); _documentSession.Advanced.Patch<User, string>("Users/131-A",
u => u.Apps["59"].RolesId
, r => r.Add("Admin")); _documentSession.Advanced.Increment<User, int>("Users/131-A", x => x.TestProp, 10);
_documentSession.Advanced.Defer(new PatchCommandData("Users/131-A", null,
new PatchRequest()
{
Script = $@"this.Apps[args.appCode] = args.app",
Values =
{
{"appCode", appCode},
{"app", new ActiveApp
{
FirstName = "عبدالصالح",
LastName = "کاشانی",
UserName = abdossaleh,
RolesId = new List<string>{"Admin"}
}
}
}
}, null)); Script = "this.Apps[args.app].Roles.splice(args.index,0,args.role)",
Values =
{
{
"index": 1 // مکانی که میخواهیم عملیات انجام شود
"app", 59
"role", "User"
}
} splice(args.index,1,args.role)
Script = @"this.Roles= this.Apps[args.app].Roles.filter(role=> role != args.role);",
Values =
{
{"app", 59}
{"role", "User"}
} _documentSession.Advanced.MaxNumberOfRequestsPerSession = 110;
using (BulkInsertOperation bulkInsert = store.BulkInsert())
{
for (int i = 0; i < 1000 * 1000; i++)
{
bulkInsert.Store(new User
{
PhoneNumber = randomPhone(),
});
}
}