[英]Entity Framework 6 - using a class with three tables (Db first)
I'm working with Entity Framework 6.我正在使用实体框架 6。
I have three tables in my database:我的数据库中有三个表:
Payments
has these columns: Payments
有这些列:
The other two tables have the same columns, but with a column called Result.其他两个表具有相同的列,但有一个名为 Result 的列。
Can I create a class Payment
with all columns and then mapping in the database just the properties I need from a case?我可以创建一个包含所有列的
Payment
类,然后在数据库中仅映射我需要的案例属性吗?
Example:例子:
public class Payment
{
public string id {get;set;}
public decimal amount {get;set;}
public string json {get;set;}
public string result {get;set;}
}
And in DbContext
:在
DbContext
:
Using(var context = new dbcontext())
{
paym = new Payment();
context.Payments.add(paym);
paym.result = "OK";
context.Payments_temp.add(paym);
context.Payments_error.add(paym);
}
If someone knows how do that, I'd really appreciate it如果有人知道怎么做,我真的很感激
Solved: Convert the clases with json serialize.解决:用json序列化转换类。
In DBContext在数据库上下文中
{
paym = new Payments();
context.Payments.add(paym);
paym.result = "OK";
var serializedPayments = JsonConvert.SerializeObject(paym);
context.Payments_temp
.add(JsonConvert.DeserializeObject<Payments_temp>(paym));
context.Payments_error
.add(JsonConvert.DeserializeObject<Payments_error>(paym));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.