I have an existing database and im having trouble using my table primary key "useridPK". I'd like to use the default "ID" as an alias of my useridPK.
My models are setup like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using System.Data.Entity;
using System.Diagnostics;
namespace myPROJECT.Models
{
[Table(Name="AskUsers")]
public class AskUser
{
[Column(Name="useridPK",IsPrimaryKey=true,IsDbGenerated=true)]
public Int32 ID { get; private set; }
[Column]
public int roleidFK { get; set; }
[Column]
public string username { get; set; }
[Column]
public string password { get; set; }
[Column]
public DateTime datecreated { get; set; }
[Column]
public string firstname { get; set; }
[Column]
public string lastname { get; set; }
}
public class myPROJECT_DBContext : DbContext
{
public DbSet<AskUser> AskUsers { get; set; }
}
}
It gives the error:
Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'ID'.
My controller code:
public ActionResult Stuff()
{
var uu = from x in db.AskUsers
开发者_JAVA技巧 select x;
return View(uu.ToList());
}
I'm not really sure if this part:
[Column(Name="useridPK",IsPrimaryKey=true,IsDbGenerated=true)]
is deprecated in MVC3?
Thanks a lot :)
According to this article: http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-released.aspx
EF Feature CTP5 Released! 6 Dec 2010 9:00 PM
The full list of data annotations supported in CTP5 is;
ColumnAttribute : Placed on a property to specify the column name, ordinal & data type
If you are using a pre-CTP5 version of EF, perhaps ColumnAttribute is not supported in that version.
精彩评论