本文介绍了如何创建使用LINQ将对象字段插入数据表的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好.我只是在学习C#,所以我试图创建Add_ABC_object_To_Database()方法以将其与新对象一起使用.请帮忙.
*数据库名称为订单,数据表名称也为订单.
Hello. I am just learning C#, so i am trying to create Add_ABC_object_To_Database() method to use it with new objects. Please help.
*Database name is Orders and datatable name is also Orders.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class ABC
{
public double Amount { get; set; }
public string Tax { get; set; }
public DateTime OrderDate { get; set; }
public void Amount()
{
amount = **some calculations here**;
}
public void Tax()
{
Tax = **some calculations here**;
}
public void OrderDate()
{
OrderDate = **some calculations here**;
}
}
public class WorkingWithDatabase
{
OrdersEntities de = new OrdersEntities();
public void Add_ABC_object_To_Database()
{
de.Orders.AddObject(
// How to construct this method
//to add ABC Class object to datatable?
// database datatable has 4 fields -
// OrderID, Amount, Tax, OrderDate
);
}
}
}
推荐答案
ABC newABC = new ABC();
newABC.Amount = 100;
newABC.Tax = 23;
newABC.OrderDate = System.DateTime.Now;
de.Orders.Add(newABC);
ABC newABC = new ABC();
newABC.Amount();
newABC.Tax();
newABC.OrderDate();
newABC.Add_ABC_object_To_Database();
这篇关于如何创建使用LINQ将对象字段插入数据表的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!