读书人

Linq奇怪有关问题

发布时间: 2012-01-08 22:48:50 作者: rapoo

Linq奇怪问题
private CustomerDataContext cd;

private CustomerDataContext GetCutomer
{
get
{
if (this.cd == null)
{
this.cd = new CustomerDataContext();
}
return this.cd;
}
}


private void InUserLoginLog(string userName, string LoginFun, string IP, string Host,bool isLogin,string Remark)
{
UserCustomerLoginLog ucl = new UserCustomerLoginLog();
ucl.isLogin = isLogin;
ucl.LoginFun = LoginFun;
ucl.LoginGuid = Tool.Tool.GetGuid();
ucl.LoginHost = Host;
ucl.LoginIP = IP;
ucl.LoginRmark = Remark;
ucl.LoginTime = DateTime.Now.ToString();
ucl.UserName = userName;
this.GetCutomer.UserCustomerLoginLog.InsertOnSubmit(ucl);
this.GetCutomer.SubmitChanges();
}

表结构和方法中的相同,字段的属性和大小都是一样的,事实上这个LINQ的表就是在建好数据库后拖进去的,但是!
{System.InvalidCastException: 指定的转换无效。
在 System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManager`2.TryCreateKeyFromValues(Object[] values, V& v)
在 System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache

为什么在执行方法时出现这种问题呢?

[解决办法]
我猜测可能是Linq本身并不是为了ORM设计的所以处理不了表之间的关联。Entity Framework的话应该能行

读书人网 >C#

热点推荐