petapoco插入问题
我有一个类定义如下:
public class Location
{
public Location()
{
Meetings = new List<Meeting>();
}
public virtual int ID { get; private set; }
public virtual string Name { get; set; }
public virtual ICollection<Meeting> Meetings { get; set; }
}
数据库表只是带有 ID 和 Name 属性的“位置”。
其他一些表“会议”有一个指向该表的外键。它超出了我在本示例中尝试处理的范围,但我认为它导致 PetaPoco 失败......
我正在尝试使用 PetaPoco 将新位置插入数据库,如下所示
public int AddLocation(string name)
{
var newLocation = new Location{Name = name};
var db = new PetaPoco.Database(_connectionString);
db.Insert("locations", "ID", newLocation);
return newLocation.ID;
}
:抛出这样的错误:
{"不存在对象类型的映射 System.Collections.Generic.List`1[[NHRepoTemplate.sampleUsage.sampleModel.Meeting, NHRepoTemplate,版本=1.0.0.0, 文化=中立,PublicKeyToken=null]] 到已知的本地托管提供商 类型。”}
导致 PetaPoco 无法执行插入操作,但是......必须有一种方法告诉它“忽略”这一点,对吗?
I have a class defined like so:
public class Location
{
public Location()
{
Meetings = new List<Meeting>();
}
public virtual int ID { get; private set; }
public virtual string Name { get; set; }
public virtual ICollection<Meeting> Meetings { get; set; }
}
And the database table for this is just “locations” with an ID and a Name property.
Some other table “meetings” has a foreign key back to this table. And it is beyond the scope of what I’m trying to work with in this example, yet I think it is causing PetaPoco to fail…
I’m trying to use PetaPoco to insert a new location into the database like this:
public int AddLocation(string name)
{
var newLocation = new Location{Name = name};
var db = new PetaPoco.Database(_connectionString);
db.Insert("locations", "ID", newLocation);
return newLocation.ID;
}
And it is throwing an error like so:
{"No mapping exists from object type
System.Collections.Generic.List`1[[NHRepoTemplate.sampleUsage.sampleModel.Meeting,
NHRepoTemplate, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null]]
to a known managed provider native
type."}
It seems to me like the existence of the child collection causes PetaPoco to not be able to do the insert, but... there must be a way to tell it to "ignore" that, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将其放在您的会议属性上:
Try putting this over your Meetings property:
如果您在 petapoco 类上方使用
[ExplicitColumns]
属性,则所有不具有[Column]
属性的属性都将被忽略if you use
[ExplicitColumns]
attribute above your petapoco class, all properties that do not have the[Column]
attribute will be ignored