I did manage to get the connection string sorted out, but now I have a different problem that I don't think will be so easy to solve without a leg up. I wrote some extremely simple code to test Entity Framework access to our database. I have a single entity class:
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Paychex.IP.Common.IPEntities
{
[Table("USERS")]
public class User
{
[Key]
public long User_Id { get; set; }
public virtual long Pclient_Id { get; set; }
public string Password { get; set; }
public string UserName { get; set; }
public string User_Description { get; set; }
public virtual long? Emp_Id { get; set; }
public bool? Employee_only { get; set; }
public bool? Must_Change_Password { get; set; }
public long? Failed_Logins { get; set; }
public DateTime? Last_Login { get; set; }
public long? Sequence_Number { get; set; }
public bool? All_Divs { get; set; }
public bool? All_Depts { get; set;
public string User_Role { get; set; }
public DateTime? Begin_Support { get; set; }
public DateTime? End_Support { get; set; }
public string One_Time_Access { get; set; }
public long? Cloned_From_User { get; set; }
public string Email { get; set; }
public string Reset_Email { get; set; }
public DateTime? Reset_Timeout { get; set; }
public long? Challenge_Failures { get; set; }
public string Perm_User_Role { get; set; }
public DateTime? Password_Changed_Date { get; set; }
}
Code: Select all
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
namespace Paychex.IP.Common.IPDBContext
{
public class IPDBContext<TContext> : DbContext where TContext : DbContext
{
static IPDBContext()
{
Database.SetInitializer<TContext>(null);
}
public IPDBContext()
: base("Name=IPDBContext")
{
}
}
public class UserSecurityContext : IPDBContext<UserSecurityContext>
{
public DbSet<User> Users { get; set; }
}
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Paychex.IP.Common.IPDBContext;
using Paychex.IP.Common.IPEntities;
namespace EntitiesConsoleTests
{
class Program
{
private static void Main(string[] args)
{
Console.Write("Press <Enter> to begin...");
Console.ReadLine();
try
{
using (var db = new UserSecurityContext())
{
var q = from usr in db.Users
orderby usr.UserName
select usr;
foreach (var u in q)
{
Console.WriteLine(u.UserName);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
Console.Write("Press <Enter>");
Console.ReadLine();
}
}
}
This is the content of app.config file for the test program:+ ex {"An error occurred while executing the command definition. See the inner exception for details."} System.Exception {System.Data.EntityCommandExecutionException}
+ q {SELECT
"Extent1"."User_Id",
"Extent1"."Pclient_Id",
"Extent1"."Password",
"Extent1"."UserName",
"Extent1"."User_Description",
"Extent1"."Emp_Id",
"Extent1"."Employee_only",
"Extent1"."Must_Change_Password",
"Extent1"."Failed_Logins",
"Extent1"."Last_Login",
"Extent1"."Sequence_Number",
"Extent1"."All_Divs",
"Extent1"."All_Depts",
"Extent1"."User_Role",
"Extent1"."Begin_Support",
"Extent1"."End_Support",
"Extent1"."One_Time_Access",
"Extent1"."Cloned_From_User",
"Extent1"."Email",
"Extent1"."Reset_Email",
"Extent1"."Reset_Timeout",
"Extent1"."Challenge_Failures",
"Extent1"."Perm_User_Role",
"Extent1"."Password_Changed_Date"
FROM "Users" "Extent1"
ORDER BY "Extent1"."UserName" ASC} System.Linq.IOrderedQueryable<Paychex.IP.Common.IPEntities.User> {System.Data.Entity.Infrastructure.DbQuery<Paychex.IP.Common.IPEntities.User>}
{SELECT Invalid expression term '{'
"Extent1"."User_Id", Identifier expected
"Extent1"."Pclient_Id", Identifier expected
"Extent1"."Password", Identifier expected
"Extent1"."UserName", Identifier expected
"Extent1"."User_Description", Identifier expected
"Extent1"."Emp_Id", Identifier expected
"Extent1"."Employee_only", Identifier expected
"Extent1"."Must_Change_Password", Identifier expected
"Extent1"."Failed_Logins", Identifier expected
"Extent1"."Last_Login", Identifier expected
"Extent1"."Sequence_Number", Identifier expected
"Extent1"."All_Divs", Identifier expected
"Extent1"."All_Depts", Identifier expected
"Extent1"."User_Role", Identifier expected
"Extent1"."Begin_Support", Identifier expected
"Extent1"."End_Support", Identifier expected
"Extent1"."One_Time_Access", Identifier expected
"Extent1"."Cloned_From_User", Identifier expected
"Extent1"."Email", Identifier expected
"Extent1"."Reset_Email", Identifier expected
"Extent1"."Reset_Timeout", Identifier expected
"Extent1"."Challenge_Failures", Identifier expected
"Extent1"."Perm_User_Role", Identifier expected
"Extent1"."Password_Changed_Date" Identifier expected
FROM "Users" "Extent1" End of expression expected
ORDER BY "Extent1"."UserName" ASC} ; expected
{"An error occurred while executing the command definition. See the inner exception for details."} Invalid expression term '{'
Code: Select all
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0"/>
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<clear/>
<add name="IPDBContext"
connectionString="User Id=INSTANTPAY_DEV;Password=IPDV_01;Server=IPDEVNV1:15211/IPDEV1;Home=OraClient11g_home3"
providerName="Devart.Data.Oracle"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
I can see from online examples is that I am missing a mapping class for the table, which Entity Framework obviously did not create for me. Can anyone tell me how I can get EF to create this code so I don't have to create it myself?
Any help would be greatly appreciated.
Thanks,
Peter