Hi i am using a simple mvc application using entity framework with firebird database.
Here is my sample code
Web.Config:
="1.0"="utf-8"
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="StudentContext" connectionString="DataSource=192.168.110.21;User=VONLINE;Password=OmugZug9;Database=dimari-server21:E:\varioBill\Databases\NETCOMNEW\NETCOM_VARIOBILL.FDB;Port=3050;Dialect=3;Charset=None;Role=VARIOBILL_ROLE;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=4096" providerName="FirebirdSql.Data.FirebirdClient" />
</connectionStrings>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="FirebirdSql.Data.EntityFramework6.FbConnectionFactory, EntityFramework.Firebird" />
<providers>
<remove invariant="FirebirdSql.Data.FirebirdClient" />
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="FirebirdSql.Data.EntityFramework6.FbProviderServices, EntityFramework.Firebird" />
</providers>
</entityFramework>
</configuration>
Global.ascx:
protected void Application_Start()
{
Database.SetInitializer<MySchoolDemoMvcApp.Models.StudentContext>(null);
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
Model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations.Schema;
namespace MySchoolDemoMvcApp.Models
{
[Table("USERS")]
public class Userdata
{
public int USER_ID { get; set; }
public string FULLNAME { get; set; }
public string USERNAME { get; set; }
}
}
and another model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MySchoolDemoMvcApp.Models
{
public class StudentContext:DbContext
{
public DbSet<Userdata> userrecords { get; set; }
}
}
Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MySchoolDemoMvcApp.Models;
namespace MySchoolDemoMvcApp.Controllers
{
public class SchoolHomeController : Controller
{
public ActionResult UserDetails(int id)
{
StudentContext Studrecords = new StudentContext();
Userdata obj = Studrecords.userrecords.Single(x=>x.USER_ID==id);
return View(obj);
}
}
}
Here is the View
@model IEnumerable< MySchoolDemoMvcApp.Models.Userdata>
@using MySchoolDemoMvcApp.Models;
@{
ViewBag.Title = "UserDetails";
}
<h2>UserDetails</h2>
<div style="background-color:Gray;color:Red"><h2>Student Deatils</h2>
<table>
@foreach (Userdata item in @Model)
{
<tr><td>
User Id:
</td><td>@item.USER_ID</td></tr>
<tr><td>
User Name:
</td><td>@item.USERNAME</td></tr>
<tr><td>
Full Name:
</td><td>@item.FULLNAME</td></tr>
}
</table>
</div>
But i am unable to connect with firebird database.During application start it is showing issue as The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
Please help me Thanks in advance