entity-framework

Hide button on view based on Auth access in Aspnet MVC - Without hard coding Authorization in Controller

时光怂恿深爱的人放手 提交于 2020-03-05 03:14:26
问题 Project Overview: Working in dashboard Views on back-end of project. I have a Permission driven Menu. Menu gets populated when User logs in and views dashboard. Currently the User sees all the buttons IE: delete, edit, details, create. I would like to hide those buttons from the view. Currently they can select it and it will redirect to a UnAuthorized page if they do not have access. I have a Menu / MenuPermissions tables that bits are set if the user has access or not. I am looking for

My NLog record is not saving. Where can I see my save failures for NLog?

亡梦爱人 提交于 2020-03-05 00:30:46
问题 I have 2 NLog database targets. The first one has been working. The second one that I just added does not seem to save when I check the table in the database.. However, I get no exception to look at for debugging.. Is there something I can turn on? Or somewhere I need to look? Maybe if there are any NLog experts, they can see a simple mistake I may have made? Here is my code for creating the NLog configuration: // nlog config (ExceptionTracking) LogManager.ThrowExceptions = true; // Using

Getting AspNet Users RoleId for Comparison In permissions

只谈情不闲聊 提交于 2020-03-05 00:24:28
问题 I have a area where the RoleId is kept as a string in the permissions table. I am doing a comparison on the Id to pull all permissions for the Role. I am getting the current Logged in user RoleId like this. var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); string roleid = userManager.FindById(User.Identity.GetUserId()).Roles.Select(r => r.RoleId); It does not like the usage of string. I am getting Cannot implicitly convert type 'System.Collections

entity framework 5.0 .load method and .local property are missing from entity

試著忘記壹切 提交于 2020-03-04 23:01:27
问题 I'm using entity framework 5 and have two Visual Studio 2010 solutions. One is a small test solution with one project and one is a much larger solution with multiple projects where I'm doing the actual business application. The entities in the smaller solution have both the .Load() method and the .Local property. The entities in the larger solution have neither. I've referenced both system.data.entity and EntityFramework in the projects. I've compared the two solutions and can't figure out

user-defined scalar function to generate computed column

雨燕双飞 提交于 2020-03-04 21:33:53
问题 I have databse having 2 tables i.e (Installment and InstallmentPlan). In the installment table there are number of columns. I want to add one new computed column name SurchargeCalculated (SC). The calculation for SC is this SC = (Installment.Amount * Installment.days * (InstallmentPlan.InstPercentage /365 /100)) I have created user-defined function SurchargeCal having 3 parameters which are Amount, days and InstPercentage. The problem is that when i add computed column in installment table

How to use views in Entity Framework?

☆樱花仙子☆ 提交于 2020-03-04 20:14:51
问题 How can I use database views in Entity Framework? I have the following view in the SQL database called pl SELECT dbo.Product.Productkey, dbo.Product.Productcode, dbo.Product.Productname, dbo.rcode.code, dbo.rcode.label FROM dbo.Product INNER JOIN dbo.rcode ON dbo.Product.programtypekey = dbo.rcode.rcodekey How can I read from the above view in application using EF? Currently I am readinmg from a table as shown below. I want to ready from view instead. In my context, I have public virtual

How to use views in Entity Framework?

柔情痞子 提交于 2020-03-04 20:14:32
问题 How can I use database views in Entity Framework? I have the following view in the SQL database called pl SELECT dbo.Product.Productkey, dbo.Product.Productcode, dbo.Product.Productname, dbo.rcode.code, dbo.rcode.label FROM dbo.Product INNER JOIN dbo.rcode ON dbo.Product.programtypekey = dbo.rcode.rcodekey How can I read from the above view in application using EF? Currently I am readinmg from a table as shown below. I want to ready from view instead. In my context, I have public virtual

How to write an extension method in DbContext class?

只谈情不闲聊 提交于 2020-03-03 07:13:25
问题 I want to create a helper method to check an item exists or not in datatabase. I've tried this: public static class DbContextExtensions { public static bool Exist<TModel>(this DbSet<TModel> model, string id) where TModel : class { return !string.IsNullOrEmpty(id) && model.SingleOrDefault(x => x.Id == id) != null; } } I'm getting this error message: 'TModel' does not contain a definition for 'Id' and no extension method 'Id' accepting a first argument of type 'TModel' could be found (are you

How to I access the DbContext of EF core from another project when used in ASP.NET core?

走远了吗. 提交于 2020-03-02 12:28:28
问题 I followed the pattern to use EF Core with ASP.NET core and all is well. But recently I created a 'Calculation' project and want to make database calls from it. The problem is I don't know how to create a new DbContextOptions . In my code that is done with services.AddDbContext<RetContext>(options => options .UseLazyLoadingProxies() .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); But in a new .NET core class I need to provide it manually. How do I do this ? My code is

How to I access the DbContext of EF core from another project when used in ASP.NET core?

风格不统一 提交于 2020-03-02 12:27:31
问题 I followed the pattern to use EF Core with ASP.NET core and all is well. But recently I created a 'Calculation' project and want to make database calls from it. The problem is I don't know how to create a new DbContextOptions . In my code that is done with services.AddDbContext<RetContext>(options => options .UseLazyLoadingProxies() .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); But in a new .NET core class I need to provide it manually. How do I do this ? My code is