EntityType & # 39; uri # 39;没有定义键
本文关键字:定义 EntityType uri | 更新日期: 2023-09-27 18:10:48
我有一个问题EF 4.1
这里是我的实体和上下文:
public class PasmISOContext : DbContext
{
public DbSet<Avatar> Avatars { get; set; }
public DbSet<User> Users { get; set; }
}
namespace PasmISO.Domain
{
public class User
{
[Key]
public string Login { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public Avatar Avatar { get; set; }
}
}
namespace PasmISO.Domain
{
public class Avatar
{
[Key]
public int Id { get; set; }
[Required]
public Uri Link { get; set; }
}
}
在mvc控制器中,我有
PasmISOContext db=new PasmISOContext();
if (db.Avatars.Count()==0)
{
db.Avatars.Add(new Avatar() { Link = new Uri("http://www.google.com/somelinktojpg") });
}
当我运行我的代码,我得到异常:
One or more validation errors were detected during model generation:
System.Data.Edm.EdmEntityType: : EntityType 'Uri' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Uris� is based on type �Uri� that has no keys defined.
有什么办法解决这个问题吗?
听起来EF不知道如何处理Uri类型;它没有SQL映射。最好的办法是将Link属性从Uri更改为string。