本文整理汇总了C#中ApplicationDbContext.Set方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationDbContext.Set方法的具体用法?C# ApplicationDbContext.Set怎么用?C# ApplicationDbContext.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationDbContext
的用法示例。
在下文中一共展示了ApplicationDbContext.Set方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveTaskCardAsync
public async Task RemoveTaskCardAsync(long taskCardId)
{
using (var db = new ApplicationDbContext())
{
var taskCard = db.Set<TaskCard>().First(x => x.TaskId == taskCardId);
db.Set<TaskCard>().Remove(taskCard);
await db.SaveChangesAsync();
}
}
示例2: GetFailedTaskCardsAsync
public async Task<List<TaskCard>> GetFailedTaskCardsAsync(int userId)
{
using (var db = new ApplicationDbContext())
{
return await db.Set<TaskCard>().Where(x => x.UserId == userId && x.Card.Status == CardStatus.Failed).ToListAsync();
}
}
示例3: GetAllTaskCardsAsync
public async Task<List<TaskCard>> GetAllTaskCardsAsync(int userId)
{
using (var db = new ApplicationDbContext())
{
return await db.Set<TaskCard>().ToListAsync();
}
}
示例4: AddTaskCardAsync
public async Task AddTaskCardAsync(TaskCard taskCard)
{
using (var db = new ApplicationDbContext())
{
db.Set<TaskCard>().Add(taskCard);
await db.SaveChangesAsync();
}
}
示例5: IsValid
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
var Name = validationContext.MemberName;
if (string.IsNullOrEmpty(Name))
{
var displayName = validationContext.DisplayName;
var prop = validationContext.ObjectInstance.GetType().GetProperty(displayName);
if (prop != null)
{
Name = prop.Name;
}
else
{
var props = validationContext.ObjectInstance.GetType().GetProperties().Where(x => x.CustomAttributes.Count(a => a.AttributeType == typeof(DisplayAttribute)) > 0).ToList();
foreach (PropertyInfo prp in props)
{
var attr = prp.CustomAttributes.FirstOrDefault(p => p.AttributeType == typeof(DisplayAttribute));
var val = attr.NamedArguments.FirstOrDefault(p => p.MemberName == "Name").TypedValue.Value;
if (val.Equals(displayName))
{
Name = prp.Name;
break;
}
}
}
}
PropertyInfo IdProp = validationContext.ObjectInstance.GetType().GetProperties().FirstOrDefault(x => x.CustomAttributes.Count(a => a.AttributeType == typeof(KeyAttribute)) > 0);
int Id = (int)IdProp.GetValue(validationContext.ObjectInstance, null);
Type entityType = validationContext.ObjectType;
var result = db.Set(entityType).Where(Name + "[email protected]", value);
int count = 0;
if (Id > 0)
{
result = result.Where(IdProp.Name + "<>@0", Id);
}
count = result.Count();
if (count == 0)
return ValidationResult.Success;
else
return new ValidationResult(ErrorMessageString);
}
}
示例6: EditTaskCardAsync
public async Task<TaskCard> EditTaskCardAsync(TaskCard taskCard)
{
using (var db = new ApplicationDbContext())
{
db.Set<TaskCard>().AddOrUpdate(taskCard);
await db.SaveChangesAsync();
return taskCard;
}
}
示例7: UpdateStatus
public async Task<TaskCard> UpdateStatus(long taskCardId, CardStatus status)
{
using (var db = new ApplicationDbContext())
{
var taskCard = db.Set<TaskCard>().First(x => x.TaskId == taskCardId);
taskCard.Card.Status = status;
await db.SaveChangesAsync();
return taskCard;
}
}
示例8: CheckUserToken
private bool CheckUserToken(string confirmationToken)
{
var context = new ApplicationDbContext();
ApplicationUser user = context.Users.SingleOrDefault(applicationUser => applicationUser.ConfirmationToken == confirmationToken);
if (user == null) return false;
user.IsConfirmed = true;
DbSet<ApplicationUser> applicationUsers = context.Set<ApplicationUser>();
applicationUsers.Attach(user);
context.Entry(user).State = EntityState.Modified;
context.SaveChanges();
return true;
}
示例9: SqlTool
public JsonResult SqlTool(string query)
{
var type = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(t => t.Name == query);
ApplicationDbContext context = new ApplicationDbContext();
DbSet contextDbSet;
contextDbSet = context.Set(type);
return Json(contextDbSet.ToString());
}
示例10: Configure
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
/// <param name="loggerFactory"></param>
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddNLog();
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
.CreateScope())
{
serviceScope.ServiceProvider.GetService<BddContext>()
.Database.Migrate();
serviceScope.ServiceProvider.GetService<ApplicationDbContext>()
.Database.Migrate();
serviceScope.ServiceProvider.GetService<BddContext>().EnsureSeedData();
}
}
catch { }
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseIdentity();
app.UseOAuthValidation();
app.UseOpenIddict();
app.UseGoogleAuthentication(new GoogleOptions()
{
ClientId = Configuration["GOOGLE_CLIENT_ID"],
ClientSecret = Configuration["GOOGLE_CLIENT_SECRET"]
});
app.UseFacebookAuthentication(new FacebookOptions()
{
AppId = Configuration["FACEBOOK_APP_ID"],
AppSecret = Configuration["FACEBOOK_SECRET_ID"]
});
app.UseMiddleware<WebAPILoggerMiddleware>();
app.UseMvc(routes =>
{
routes.MapRoute("journee",
template: "Journee/Index/{equipe}/{idJournee}", defaults: new { controller = "Journee", action="Index", equipe="equipe1", idJournee = 1});
routes.MapRoute("actu",
template: "Journee/Detail/{url}", defaults: new { controller = "Journee", action = "Index", equipe = "equipe1", idJournee = 1 });
routes.MapRoute(
name: "default",
template: "{controller=Actu}/{action=Index}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUi();
app.AddNLogWeb();
using (var context = new ApplicationDbContext(app.ApplicationServices.GetRequiredService<DbContextOptions<ApplicationDbContext>>()))
{
context.Database.EnsureCreated();
var applications = context.Set<OpenIddictApplication>();
// Add Mvc.Client to the known applications.
if (!applications.Any())
{
// Note: when using the introspection middleware, your resource server
// MUST be registered as an OAuth2 client and have valid credentials.
//
// context.Applications.Add(new OpenIddictApplication {
// Id = "resource_server",
// DisplayName = "Main resource server",
// Secret = Crypto.HashPassword("secret_secret_secret"),
// Type = OpenIddictConstants.ClientTypes.Confidential
// });
applications.Add(new OpenIddictApplication
{
ClientId = "xamarin-auth",
ClientSecret = Crypto.HashPassword(Configuration["OPENIDDICT_CLIENT_SECRET"]),
DisplayName = "HOFC",
LogoutRedirectUri = "https://local.webhofc.fr/",
RedirectUri = "urn:ietf:wg:oauth:2.0:oob",
//.........这里部分代码省略.........
示例11: ExternalLoginCallback
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
var externalIdentity = HttpContext.GetOwinContext().Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
var emailClaim = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);
var email = emailClaim.Value;
var nameClaim = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name);
var name = nameClaim.Value;
// Sign in the user with this external login provider if the user already has a login
var user = await UserManager.FindAsync(loginInfo.Login);
if (user != null)
{
await SignInAsync(user, isPersistent: false);
return RedirectToLocal(returnUrl);
}
else
{
// If the user does not have an account, then prompt the user to create an account
// If the user does not have an account, then create one for them.
ViewBag.ReturnUrl = returnUrl;
ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
using (ApplicationDbContext db = new ApplicationDbContext())
{
Int32 count = db.Set<IdentityUser>().Count();
var user1 = new ApplicationUser() { UserName = "user" + count.ToString() };
var result = await UserManager.CreateAsync(user1);
if (result.Succeeded)
{
result = await UserManager.AddLoginAsync(user1.Id, loginInfo.Login);
if (result.Succeeded)
{
var appuser = new AppUser() { UserID = user1.Id, Email = email, Name = name };
db.AppUsers.Add(appuser);
db.SaveChanges();
await SignInAsync(user1, isPersistent: false);
return RedirectToLocal(returnUrl);
}
}
}
return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { UserName = loginInfo.DefaultUserName });
}
}
示例12: GiftRepository
//Constuctor
public GiftRepository(ApplicationDbContext dbContext)
{
_dbContext = dbContext;
_dbSet = dbContext.Set<Gift>();
}