首页 \ 问答 \ 如何将嵌套对象从一种类型转换为另一种类型(How to convert nested object from one type to another)

如何将嵌套对象从一种类型转换为另一种类型(How to convert nested object from one type to another)

我有一个结构类似的C#对象

class Source 
{
    public int Id {get; set;}
    public List<Source> Children {get; set;}
}

我想将Source类型的对象(具有未知数量的Children )转换为Destination类型的对象

class Destination
{
    public int key {get; set;}
    public List<Destination> nodes {get; set;}
}

有没有办法可以使用LINQ执行此操作,或者我必须遍历所有并映射它。


I have a C# object with structure like

class Source 
{
    public int Id {get; set;}
    public List<Source> Children {get; set;}
}

I want to convert an object of type Source (with unknown number of Children) to object of type Destination

class Destination
{
    public int key {get; set;}
    public List<Destination> nodes {get; set;}
}

Is there a way I can do this using LINQ or do I have to loop through all and map it.


原文:https://stackoverflow.com/questions/27706092
更新时间:2023-02-02 06:02

最满意答案

好吧,我通过在/conf/context.xml中输入我的jdbc连接信息,通过无法为连接 URL'null '创建类''的JDBC驱动程序提供的解决方案

看起来像一个创可贴而不是一个解决方案,但它确实有效。


Well, I got this to work via the solution provided in Cannot create JDBC driver of class '' for connect URL 'null' , by putting in my jdbc connection information in /conf/context.xml

Seems like a band-aid more than a solution, but it does work.

相关问答

更多
  • 另一种解决方案是(它适用于我),从web.xml中删除资源ref,从服务器中删除资源。 xml并从context.xml中删除ResourceLink。 仅将资源添加到context.xml中,
    我认为这是因为您的应用程序在使用后没有关闭连接。 请检查您的代码并确保所有连接在使用后关闭。 I think this is because your application not closing connections after use. Please check your code and make sure all connections are closing after use.
  • 在询问之后,看起来问题是XtraBackup对数据库服务器造成的压力。 虽然XtraBackup不对所有InnoDB数据库使用锁定,但它仍然会给系统带来压力。 从文档中 “虽然innobackupex不会阻止数据库的操作,但任何备份都可以为正在备份的系统增加负载。在没有太多备用I / O容量的系统上,限制innobackupex读取和写入InnoDB的速率可能会有所帮助您可以使用--throttle选项执行此操作。“ 我们最终只是碰到了maxActive而不是选择限制。 当XtraBackup最初运行时,查 ...
  • 固定 打开终端并打开MAMP的mysql数据库文件夹: sudo chown -R `whoami`:admin /Applications/MAMP/db/mysql 说明 我刚遇到同样的错误,提示在这里: [错误] InnoDB:./ ib_logfile0无法在读写模式下打开。 这意味着不允许运行mysqld的用户进行读写。 但_mysql是此文件的所有者: -rw-r ----- 1 _mysql admin 50331648 10 avr 22:35 ib_logfile0 我跑了ps -axj ...
  • 您需要为开发使用正确的J2EE版本( <1.5 )。 您还需要定义要在web.xml使用的兼容servlet版本,即
    好吧,我通过在/conf/context.xml中输入我的jdbc连接信息,通过无法为连接 URL'null '创建类''的JDBC驱动程序提供的解决方案 看起来像一个创可贴而不是一个解决方案,但它确实有效。 Well, I got this to work via the solution provided in Cannot create JDBC driver of class '' for connect URL 'null' , by putting in my jdbc connection i ...
  • 它似乎是一个classLoader问题,在liferay中有不同的类加载器(粗略解释): Plugin Class Loader:加载插件的类,例如从'/ my-portlet / WEB-INF / lib /' Portal类加载器:从portal-impl.jar加载门户类 全局类加载器:加载服务器类,即../tomcat-7.0.27/lib/ext/类 因此,有不同的方法可以将DynamicQuery类从一个classLoader加载到另一个classLoader中。 以下是根据实现类所在的位置使 ...
  • Tomcat使用工厂来创建JNDI资源。 对于有限数量的资源类型(包括javax.sql.DataSource),Tomcat知道它可以使用内置工厂。 对于未知资源类型(例如jcom.jolbox.bonecp.BoneCPDataSource),您需要指定用于创建资源的工厂。 Tomcat uses factories to create JNDI resources. For a limited number of resource types (including javax.sql.DataSour ...
  • 这里有两个任务,从LDAP导入用户并使用CAS对用户进行身份验证。 您可以从“控制面板”(UI)或portal-ext.properties文件进行配置。 如果使用这两种方法进行配置并且存在属性冲突,则“控制面板”设置优先。 从LDAP导入用户并不困难(我已经在5.2.3和6.1中完成了),尽管导入/不导入密码可能会令人困惑。 尝试首先处理此任务,并确保您能够对LDAP进行身份验证。 我建议使用身份验证链(多种身份验证方法,如果一种方法失败,将尝试第二种方法,等等)。 如果在CAS中断的情况下以这种方式配置 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。