问题描述
我正在使用包含实体和列名的映射文件来执行插入,这样可以通过实体框架来完成?
I am using a mapping file that contains the Entity and the Column Names to perform the insert on so can this be done with entity framework ?
替代版本只是使用内联SQL并编写代码,如
The alternative version is just to use inline SQL and write code like
sql = INSERT INTO+ someTable + etc ....
sql = INSERT INTO " + someTable + etc....
推荐答案
我不认为使用实体框架(EF)将会很适合这个项目您正在开展工作。使用EF的主要优点之一是对象图;它负责识别新记录,更新记录等。
I don't think using Entity Framework (EF) will be a good fit for this project you're working on. One of the main benefits of using EF is the object graph; it takes care of recognizing new records, updated records and so on.
如果您正在使用动态对象和表,您真正只知道底层数据存储在运行时的位置,那么我将选择使用参数化存储过程的通用数据库类。
If you are working with dynamic objects and tables where you truly only know where your underlying data store is at runtime, then I would opt for using a generic database class with parameterized stored procedures.
显然,实体框架已经非常受欢迎,但是,执行SQL的方式没有任何问题,EF不一定是与数据库交互的唯一方式。
Obviously the Entity Framework has gotten incredibly popular, but, there's nothing wrong with executing SQL the ol' fashioned way. EF doesn't have to be the only way you interact with your database.
这篇关于实体/属性只在运行时才知道如何使用实体框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!