If you want to get data from an external source then I would suggest using the classic approach and creating a connection string and then access the DB with dotnet core capabilities .
OR
If you want to extend the current DB and have a better performance and managability then I would suggest this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Intranet.Models
{
[Table("Department")]
public class Department
{
[Key]
public int DeptID { get; set; }
[DisplayName("Department Name")]
public string DeptName { get; set; }
public bool DeptActive { get; set; }
}
}
Models/IdentityModels.cs
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
namespace Intranet.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<Department> Department { get; set; }
public ApplicationDbContext()
: base("serviceDirectory", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
}
Controllers/DepartmentController.cs
using Microsoft.AspNetCore.Mvc;
using Intranet.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace Intranet.Controllers
{
public class DepartmentController : Controller
{
private ApplicationDbContext db;
public DepartmentController()
{
db = new ApplicationDbContext();
}
// GET: Departments
public ActionResult Index()
{
return View(db.Department.Where(d => d.DeptActive).ToList());
}
protected override void Dispose(bool disposing)
{
db.Dispose();
}
}
}
foreach statement cannot operate on variables of type
'TelephoneDirectory' because 'TelephoneDirectory' does not contain a
public instance or extension definition for 'GetEnumerator'
Connect to another SQL Database
Hi all,
I have an umbraco 10 project which is working fine, however, I want a page which will link to another SQL database separate from Umbraco.
This will just be getting some basic information from a database to display.
Are there any guides around this? I'm using EntityFramework at the moment but cant get my head around it.
Cheers
If you want to get data from an external source then I would suggest using the classic approach and creating a connection string and then access the DB with dotnet core capabilities .
OR
If you want to extend the current DB and have a better performance and managability then I would suggest this:
Hi,
I did trying using EntityFramework
This is what I have.
Models/DepartmentModel.cs
Models/IdentityModels.cs
Controllers/DepartmentController.cs
Then on my template page on Umbraco I have
But I'm getting the following error;
is working on a reply...