- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题:
问:为什么我不能/如何动态使用 DataTable 中的数据在使用反射(?)的函数中制作 LINQ/EF,以根据可用内容创建实体实例?
我看过很多关于硬编码的问答,但没有一个是关于动态的。我正在寻找一种替代方法,而不是必须为我的所有实体维护硬编码代码...
我的方法的背景/验证:
给定:-我知道类的名称(来自 dt.Name),并且我已经验证它是一个有效的实体。- 我知道我将使用每个 DataRow 更新的列的名称,因为它们在 dt 的列名称中。
问题重述,现在有上下文:为什么不能/如何动态使用 DataTable 中的数据在使用反射(?)的函数中制作 LINQ/EF,以根据可用的内容创建实体的实例?
[Pseudo-Code]
public void DataTableToEntities(DataTable dt){
string entityClassName = dt.Name;
ArrayList/List<string> colNames = dt.Columns. names, ...
....
using (MyContext ctx = new MyContext()){
while (row dtRow in dtRows){
// magic follows:
DeterminedEntity de = new DeterminedEntity();
// populate de with dtRow
ctx.[DeterminedEntity].Add(de);
// magic ends...
}
ctx.SaveChanges;
}
}
理由:
我可以随意添加、编辑和删除实体,而不必像上面那样在导入场景中硬编码那些细微的变化。
下一步:使用 WorkBook -> DataSet 和 WorkSheets -> DataTables 处理动态工作簿和工作表创建作为上述过程的上传模板。
进度:2016 年 11 月 6 日
这个问题的症结似乎是如何仅从名称实例化 DBContext 类实体的实例。
我的 Scratch 控制台应用程序是一个单独的项目(相同的解决方案),所有模型和东西都复制过来......
到目前为止我有:
static void Main(string[] args)
{
ScratchProgram s = new ScratchConsole1.ScratchProgram();
Console.WriteLine("starting");
string fileLocation = @"C:\Users\...\SomeDbSetClass_test.xlsx";
string tableName = "SomeDbSetClass";
//----------------------------------------------------------
// FreeSpire.xls
Workbook wb = new Workbook();
wb.LoadFromFile(fileLocation);
Console.WriteLine("wb.WorkSheets count: " + wb.Worksheets.Count);
//----------------------------------------------------------
Worksheet ws = wb.Worksheets[tableName];
Console.WriteLine("ws.Rows count: " + ws.Rows.Count());
//----------------------------------------------------------
DataTable dt = new DataTable(tableName);
dt = ws.ExportDataTable();
Console.WriteLine("dt.Rows.Count: " + dt.Rows.Count);
Console.WriteLine("dt.Name: " + dt.TableName);
//==========================================================
string pathToAssembly = @"C:\...\ScratchConsole1.dll";
var aClass = s.CreateInstanceOf(dt.TableName, pathToAssembly);
// Now I have a valid class of the program-NOT the ef ctx...
Console.WriteLine("aClass.FullName: " + aClass.GetType().FullName);
MethodInfo[] aMethods = aClass.GetType().GetMethods();
// now I have an array of all get/sets... "get_<method>" and "set_<method>"
// let's iterate through all the methods, printing them:
for (int i2 = 0;i2 < aMethods.Count() ; i2++)
{
MethodInfo mi = aMethods[i2];
Console.WriteLine("method: " + mi.Name);
}
// the above isn't really useful, as I already have the property names in the dt header row
using (DatabaseContext ctx = new DatabaseContext())
{
//==========================================================
// i is used as column index below, as dr.ItemArray is an array...
int i = 0;
// each dr should create a new instance of the ctx's ef class...
foreach (DataRow dr in dt.Rows)
{
???
...Create new instance in ctx, using as class name: dt.TableName...
ctxClass <--- assuming made using aClass
???
// now we can load each class property with the value from the dr:
foreach (string drItem in dr.ItemArray)
{
Console.WriteLine(String.Format("================= col ================="));
string entAttrName = dt.Columns[i].ToString(); // this is fine as string, but...
string entAttrValue = dr[i].ToString(); // this is NOT <--- see Note1 below
Console.WriteLine("[" + i + "] Item: " + entAttrName.ToString());
Console.WriteLine("[" + i + "] Value: " + entAttrValue.ToString());
???
ctxClass.[entAttrName.ToString()] = entAttrValue.ToString(); <--- see Note1 below
???
//==============================================================================
// Note1:
// the above is far less than ideal, as it has every column/attribute/property type // being used as a String... Obviously, we want to leave doubles as doubles, ints as // ints, etc.
// This becomes a MUCH larger problem when we introduce entities as properties...
// like a State entity with many City entities as a List<State> as a property...
//==============================================================================
i++;
}
ctx.[ef class].Add(ctxClass);
}
ctx.SaveChanges();
}
Console.WriteLine("end.");
Console.ReadKey();
}
public object CreateInstanceOf(string ClassName, string AssemblyFullPath)
{
var assemblyFullPath = Assembly.LoadFrom(@"C:\...\ScratchConsole1.exe");
var assembly = Assembly.GetExecutingAssembly();
var type = assembly.GetTypes().First(t => t.Name == ClassName);
return Activator.CreateInstance(type);
}
我希望这能让事情更容易理解。:)
更新和解决方案! SO 用户,Gert Arnold ,通过在 this post 上更改的单行解决了问题:
// All details from the property to update/set:
//PropertyInfo theProp = thisTypeInfo.GetDeclaredProperty(entAttrName);
PropertyInfo theProp = thisTypeInfo.GetProperty(entAttrName);
格特的解释:
thisTypeInfo.GetDeclaredProperty gets properties declared by the typeitself, not its supertype. Use thisTypeInfo.GetProperty. – Gert Arnold
我不敢相信我能够以一种更聪明的人可以解决的方式来构建一个我几乎不理解的问题!
============================================= ============================
最佳答案
这里一句话解决:
此程序采用电子表格文件 (.xlsx),读取 EF DbSet 类的选项卡名称以及属性名称和值的列名称和值,并将它们作为单独的实体保存在 EF 安装的数据存储中(适用于 SQLite 和 SQL Server 2014)。
很酷的部分是,应用程序中无需对 EF 类名称、属性等进行硬编码。这意味着您可以创建一个 Excel 模板,让某人填写(只需您在模板中提供的列),并且可以轻松导入该文件。
您需要为自己重新创建的一切都在这篇文章中。
我想为我自己正在编写的应用程序使用它,令我有点惊讶的是没有人愿意做同样的事情。有了 100 个 EF 类和基类,答案(即使在这里)就是埋头苦干,硬编码一切。
我将尽可能完整地在此处发布工作代码。对于任何试图使他们的软件更易于使用的人来说,这段代码有望向前迈出一大步。为了完全隔离问题/Poc/Answer,我使用了:
VS 2015,SQLite 最新版本,SQLite.CodeFirst,System.Data.SQLite[.Linq 和 .EF6](<- 可能不是全部都需要,但我第一次使用 SQLite 时遇到了困难),NLog,NLog.Config,Spire .XLS、EF6……应该是这样。一切都在 NuGet 中完成。
注意事项:
- 我在我的正常系统中使用 SQL 2014 Ent,但发现 SQLite 具有相同的性能。事实上,这个例子和下面的时间是在 SQLite 数据库文件上的!
-下面的时间是在我的开发笔记本电脑上,它在带有 VS2015 的 VirtBox VM 中运行 Win10。同一台笔记本电脑上的另一台虚拟机正在运行 SQL 2014 Enterprise,但对于这个测试示例,我在同一台 Win10 虚拟机上使用了 SQLite。
-我的 MyDbContext.cs 和 Configuration.cs 文件很简单,没有种子等。
public DbSet<Person> Persons { get; set; }
public DbSet<Child> Children { get; set; }
-有一个简单的 test.xlsx 文件,其中包含要插入到数据库中的值。
这是它的 .csv:
sChildFoo,iChildBar,dChildBaz,PersonAge,PersonWeight,PersonName
Norwich,29884,1.2,34,123,Fred Flintstone
Waterford,34990,3.4,56,210,Barney Rubble
重要提示:工作表中的选项卡标记为 Child - 与您希望加载值的类完全相同。有 2 个数据/实体类,Person() 和 Child(),称为 PersonChild.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DynamicEFLoading
{
public abstract class Person
{
[Key]
public int PersonId { get; set; }
public int PersonAge { get; set; }
public int PersonWeight { get; set; }
public string PersonName { get; set; }
}
class Child : Person
{
[Key]
[Column(Order = 0)]
public int Id { get; set; }
public string sChildFoo { get; set; }
public int iChildBar { get; set; }
public double dChildBaz { get; set; }
}
}
如您所见,所有 Child() 实例都从 Person() 继承属性。我什至将 Person() 抽象化了。
这是我在评论中敢于修饰的内容,TestProgram.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;
using NLog;
using System.Reflection;
using System.Data.Entity;
using Spire.Xls;
using System.Data;
using System.Collections;
namespace DynamicEFLoading
{
class TestProgram
{
private static Logger logit = LogManager.GetCurrentClassLogger();
static void Main()
{
DateTime dtStart = new DateTime(DateTime.Now.Ticks);
DateTime dtStop = new DateTime();
TestProgram s = new TestProgram();
Utils u = new Utils();
s.p("Starting at " + DateTime.Now.ToLongTimeString());
// for this test, I leave this door open the whole time...
using (MyDbContext ctx = new MyDbContext())
{
//###########################################################################
//
// create a row in db each time run...
//
Random rnd = new Random();
//
Child c1 = new DynamicEFLoading.Child();
// Age, Weight, Name all come from base class Person()
c1.PersonAge = rnd.Next(120);
c1.PersonWeight = rnd.Next(85, 300);
c1.PersonName = String.Format("{0} {1}", Utils.GenerateName(6), Utils.GenerateName(8));
s.p(String.Format("Created .Name: {0}", c1.PersonName));
//
c1.dChildBaz = rnd.NextDouble();
c1.iChildBar = rnd.Next(99999);
c1.sChildFoo = String.Format("{0}", Utils.GenerateName(10));
s.p(String.Format("Created .sParentFoo: {0}", c1.sChildFoo));
//
ctx.Children.Add(c1);
//_______________________________________________________
ctx.SaveChanges();
//###########################################################################
//
// in production, there would be no hard coding...
//
string fileLocation = @"C:\Users\<some user>\Desktop\test.xlsx";
//
// NOTE! Here I am specifying the only tab(ws name) in the wb. This is easily changed
// to access all tabs by index, using Worksheet ws = wb.Worksheets[index], and
// a simple loop through them all. In my first test, I even verify the tab had
// a corresponding table in DB before continuing...
string tableName = "Child";
//----------------------------------------------------------
// freeSpire.xls
Workbook wb = new Workbook();
wb.LoadFromFile(fileLocation);
//----------------------------------------------------------
// see NOTE! just above...
Worksheet ws = wb.Worksheets[tableName];
//----------------------------------------------------------
// create a DataTable
DataTable dt = new DataTable(tableName);
// load it with data from whoile worksheet (ws)
dt = ws.ExportDataTable();
// from now on, we use DataTable-not spreadsheet
//----------------------------------------------------------
s.p(String.Format("wb.WorkSheets count: " + wb.Worksheets.Count));
s.p(String.Format("ws.Rows count: " + ws.Rows.Count()));
s.p(String.Format("dt.Rows.Count: " + dt.Rows.Count));
s.p(String.Format("dt.Name: " + dt.TableName));
//==========================================================
// getting assembly name programmatically fails when a project is inside a solution
// in VS. It assumes ...\ProjName\ProjName\... whis isn't how solutions go...
string pathToAssembly = @"C:\Users\<some user>\Documents\Visual Studio 2015\Projects\DynamicEFLoading\DynamicEFLoading\bin\Debug\DynamicEfLoading.exe";
// string pathToAssembly = @".\DynamicEfLoading.exe";
// create an 'anonymous', or ghost class:
var aClass = u.CreateInstanceOf(dt.TableName, pathToAssembly);
// display class type
s.p(String.Format("aClass.FullName: " + aClass.GetType().FullName));
//==========================================================
//
// creating a DbSet for the dt's entities. It isn't good enough to just create
// the class itself-it needs to be from the DbContext (ctx). or else you can't
// ctx.SaveChanges();
//
s.p(String.Format("Creating 'dbs' object..."));
DbSet dbs = ctx.Set(aClass.GetType());
// But you can't att attributes/properties to a DbSet-only to the class it is
// derived from, so we then use the DbSet (dbs) for this class to create an
// empty class that we can populate & later add to DB via ctx:
var theObj = dbs.Create(aClass.GetType());
// make sure it's the right one:
s.p(String.Format("GetType: " + theObj.GetType()));
//____________________________________________________________________________
int i = 0; // used to keep track of each column as we go through the dt
foreach (DataRow dr in dt.Rows) // each dr in the dt is a separate instance of the theObj class
{
s.p(String.Format("================= row =================================="));
i = 0; // I don't like to put var instantiation in a loop...
// each drItem is the content for the row (theObj)
foreach (string drItem in dr.ItemArray)
{
s.p(String.Format("================= col {0} ", i));
string entAttrName = dt.Columns[i].ToString();
string entAttrValue = dr[i].ToString();
// column (property) name:
s.p("[" + i + "] Item: " + entAttrName.ToString());
// the value of that property to load into this class' property
s.p("[" + i + "] Value: " + entAttrValue.ToString());
// which type of data is this property? (string, int32, double...)
// -also has data like if nullable, etc. of use in later refinements...
TypeInfo thisTypeInfo = theObj.GetType().GetTypeInfo();
// All details from the property to update/set:
PropertyInfo theProp = thisTypeInfo.GetProperty(entAttrName);
//___________________________________________________________________
// need to determine the property type, converting entAttrValuefrom string:
// good debugging info at this stage to see what we've discovered from the class dynamically at rn time...
s.p("theProp.DeclaringType.FullName of attr: " + theProp.DeclaringType.FullName);
s.p("theProp.GetSetMethod(true).ToString() of attr: " + theProp.GetSetMethod(true).ToString());
s.p("theProp.GetType().ToString() of attr: " + theProp.GetType().ToString());
s.p("theProp.Name of attr: " + theProp.Name);
s.p("theProp.PropertyType.ToString() of attr: " + theProp.PropertyType.ToString());
s.p("theProp.ReflectedType.ToString() of attr: " + theProp.ReflectedType.ToString());
s.p("theProp.ReflectedType.ToString() of attr: " + theProp.SetMethod.ReturnType.ToString());
/* update entAttrName with entAttrValue:
*
* At this point, my values in the DataTable are all strings, but the class itself
* stores that value as who-knows-what. So here I just parse out what kind it is from three
* common types. In future, may need to add more, but for now, these are the big 4:
*
* String, Integer, DatTime, and Double
*/
if (theProp.PropertyType.ToString() == "System.String")
{
theProp.SetValue(theObj, (String)entAttrValue);
logit.Debug("Set {0} value: {1}",
theProp.PropertyType.ToString(),
entAttrValue);
}
else if (theProp.PropertyType.ToString().Contains("System.Int32"))
{
theProp.SetValue(theObj, int.Parse(entAttrValue));
logit.Debug("Set {0} value: {1}",
theProp.PropertyType.ToString(),
entAttrValue);
}
else if (theProp.PropertyType.ToString().Contains("System.DateTime"))
{
IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true);
DateTime dTime = DateTime.Parse(entAttrValue, culture, System.Globalization.DateTimeStyles.AssumeLocal);
theProp.SetValue(theObj, entAttrValue);
logit.Debug("Set {0} value: {1}",
theProp.PropertyType.ToString(),
entAttrValue);
}
else if (theProp.PropertyType.ToString().Contains("System.Double"))
{
theProp.SetValue(theObj, double.Parse(entAttrValue));
logit.Debug("Set {0} value: {1}",
theProp.PropertyType.ToString(),
entAttrValue);
}
else
{
logit.Error("Unexpected property type: {0} given. string value: {1}",
theProp.PropertyType.ToString(),
entAttrValue
);
}
i++; // increment column index...
} // end foreach (string drItem in dr.ItemArray...
// add class to context...
dbs.Add(theObj);
// to save one by one (each row):
ctx.SaveChanges();
} // end of foreach (DataRow dr in dt.Rows...
// or... to save as batch (at end of worksheet):
// ctx.SaveChanges();
//###########################################################################
dtStop = new DateTime(DateTime.Now.Ticks);
TimeSpan tsDuration = dtStop - dtStart;
s.p(String.Format("end... took {0} seconds.", tsDuration.TotalSeconds.ToString()));
Console.ReadKey();
} // end using DbContext...
}
/*
* Convenience; writes to both...
*
*/
//private static void p(string message)
private void p(string message)
{
logit.Info(message);
Console.WriteLine(message);
}
}
}
最后,这是包含 Utils() 类的 Utils.cs 文件。您会看到上面提到的这些称为“u.*”,在 TestProgram.cs 顶部实例化的方式:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using NLog;
using System.Collections;
using System.Data;
namespace DynamicEFLoading
{
class Utils
{
private static Logger logit = LogManager.GetCurrentClassLogger();
public ArrayList HeadersFromDataTable(DataTable theDataTable)
{
ArrayList arHeaders = new ArrayList();
try
{
arHeaders.AddRange(theDataTable.Columns);
logit.Info("loaded {0} column headers...", arHeaders.Count);
}
catch (Exception ex)
{
logit.Fatal("exception: " + ex.ToString());
}
return arHeaders;
}
public object CreateInstanceOf(string ClassName, string AssemblyFullPath)
{
var assemblyFullPath = Assembly.LoadFrom(@"C:\Users\<some user>\Documents\Visual Studio 2015\Projects\PoliticWebSite\ScratchConsole1\bin\Debug\ScratchConsole1.exe");
var assembly = Assembly.GetExecutingAssembly();
//var assembly = Assembly.LoadFrom(assemblyFullPath);
var type = assembly.GetTypes().First(t => t.Name == ClassName);
return Activator.CreateInstance(type);
}
public static string GenerateName(int len)
{
Random rndSeed = new Random(DateTime.Now.Millisecond);
Random r = new Random(rndSeed.Next());
string[] consonants = { "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "l", "n", "p", "q", "r", "s", "sh", "zh", "t", "v", "w", "x" };
string[] vowels = { "a", "e", "i", "o", "u", "ae", "y" };
string Name = "";
Name += consonants[r.Next(consonants.Length)].ToUpper();
Name += vowels[r.Next(vowels.Length)];
int b = 2; //b tells how many times a new letter has been added. It's 2 right now because the first two letters are already in the name.
while (b < len)
{
//_________________________________________________________________
rndSeed = new Random(DateTime.Now.Millisecond);
r = new Random(rndSeed.Next());
Name += consonants[r.Next(consonants.Length)];
b++;
//_________________________________________________________________
rndSeed = new Random(DateTime.Now.Millisecond);
r = new Random(rndSeed.Next());
Name += vowels[r.Next(vowels.Length)];
b++;
//_________________________________________________________________
}
return Name;
}
}
}
那么当程序遍历每一列(可以按任何顺序,顺便说一句)时,这一切看起来像什么?
2016-11-08 22:18:14.2500 INFO Starting at 10:18:14 PM
2016-11-08 22:18:14.3499 INFO Created .Name: Tytaetae Tytaetaetae
2016-11-08 22:18:14.3499 INFO Created .sParentFoo: Baebabababa
2016-11-08 22:18:15.2181 INFO wb.WorkSheets count: 2
2016-11-08 22:18:15.2181 INFO ws.Rows count: 3
2016-11-08 22:18:15.2338 INFO dt.Rows.Count: 2
2016-11-08 22:18:15.2338 INFO dt.Name: Child
2016-11-08 22:18:15.2487 INFO aClass.FullName: DynamicEFLoading.Child
2016-11-08 22:18:15.2487 INFO Creating 'dbs' object...
2016-11-08 22:18:15.2644 INFO GetType: DynamicEFLoading.Child
2016-11-08 22:18:15.2644 INFO ================= row ==================================
2016-11-08 22:18:15.2644 INFO ================= col 0
2016-11-08 22:18:15.2801 INFO [0] Item: sChildFoo
2016-11-08 22:18:15.2801 INFO [0] Value: Norwich
2016-11-08 22:18:15.2801 INFO theProp.DeclaringType.FullName of attr: DynamicEFLoading.Child
2016-11-08 22:18:15.2958 INFO theProp.GetSetMethod(true).ToString() of attr: Void set_sChildFoo(System.String)
2016-11-08 22:18:15.2958 INFO theProp.GetType().ToString() of attr: System.Reflection.RuntimePropertyInfo
2016-11-08 22:18:15.3114 INFO theProp.Name of attr: sChildFoo
2016-11-08 22:18:15.3114 INFO theProp.PropertyType.ToString() of attr: System.String
2016-11-08 22:18:15.3271 INFO theProp.ReflectedType.ToString() of attr: DynamicEFLoading.Child
2016-11-08 22:18:15.3271 INFO theProp.ReflectedType.ToString() of attr: System.Void
2016-11-08 22:18:15.3271 DEBUG Set System.String value: Norwich
2016-11-08 22:18:15.3428 INFO ================= col 1
...
2016-11-08 22:18:16.1237 INFO ================= row ==================================
2016-11-08 22:18:16.1394 INFO ================= col 0
2016-11-08 22:18:16.1394 INFO [0] Item: sChildFoo
2016-11-08 22:18:16.1551 INFO [0] Value: Waterford
2016-11-08 22:18:16.1551 INFO theProp.DeclaringType.FullName of attr: DynamicEFLoading.Child
2016-11-08 22:18:16.1551 INFO theProp.GetSetMethod(true).ToString() of attr: Void set_sChildFoo(System.String)
2016-11-08 22:18:16.1707 INFO theProp.GetType().ToString() of attr: System.Reflection.RuntimePropertyInfo
2016-11-08 22:18:16.1863 INFO theProp.Name of attr: sChildFoo
2016-11-08 22:18:16.1863 INFO theProp.PropertyType.ToString() of attr: System.String
2016-11-08 22:18:16.1863 INFO theProp.ReflectedType.ToString() of attr: DynamicEFLoading.Child
2016-11-08 22:18:16.2020 INFO theProp.ReflectedType.ToString() of attr: System.Void
2016-11-08 22:18:16.2020 DEBUG Set System.String value: Waterford
2016-11-08 22:18:16.2179 INFO ================= col 1
...
2016-11-08 22:18:16.5772 INFO ================= col 5
2016-11-08 22:18:16.5772 INFO [5] Item: PersonName
2016-11-08 22:18:16.5772 INFO [5] Value: Barney Rubble
2016-11-08 22:18:16.5772 INFO theProp.DeclaringType.FullName of attr: DynamicEFLoading.Person
2016-11-08 22:18:16.5927 INFO theProp.GetSetMethod(true).ToString() of attr: Void set_PersonName(System.String)
2016-11-08 22:18:16.5927 INFO theProp.GetType().ToString() of attr: System.Reflection.RuntimePropertyInfo
2016-11-08 22:18:16.5927 INFO theProp.Name of attr: PersonName
2016-11-08 22:18:16.6084 INFO theProp.PropertyType.ToString() of attr: System.String
2016-11-08 22:18:16.6084 INFO theProp.ReflectedType.ToString() of attr: DynamicEFLoading.Child
2016-11-08 22:18:16.6240 INFO theProp.ReflectedType.ToString() of attr: System.Void
2016-11-08 22:18:16.6240 DEBUG Set System.String value: Barney Rubble
2016-11-08 22:18:16.6397 INFO end... took 2.391686 seconds.
2.4 秒加载文件,将其解析为 DataSet/DataTable,然后将它们转换为类和 EF 实例,检查每一列的有效性。全部在 Linux 笔记本电脑上的 Win10 虚拟机中。
现在,我为您提供(我困惑且低效的)解决方案来获取和保存 EF 数据,除了 Excel 模板的标题行之外,无需对任何内容进行硬编码。
待办事项:
- 添加循环遍历工作簿,处理所有工作表。
- 添加验证数据表中指示的类确实存在于 EF 中(我在我的试验代码中这样做)。
- 添加验证文件是一个有效的.xlsx文件(Spire有这个功能)在导入之前等。
我花了很多时间来让它工作,而且由于我的正常编程超出了我的头脑,我将不胜感激任何关于让它变得更好/更安全/等等的反馈。我主要是通过 Intellisense 和书籍跌跌撞撞来做到这一点。
============================================= ===================
关于c# - 实体的动态数据表*无需*提前硬编码......?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40453458/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!