c# - 如何在 PetaPoco 中检索 xml 列

标签 c# sql-server ado.net petapoco

我在 sql (msql-server) 中使用 nvarchar 数据类型来描述描述。 但我想将该列更改为 xml 数据类型。 在我的 c# 数据层中,我使用 petapoco 获取数据,它使用 Ado.Net DataReader。

所以

poco对象:

[PetaPoco.TableName("sqlTableName")]
[PetaPoco.PrimaryKey("ID")]
public class PlainObj
{
    public int ID { get; set; } //(int, not null)
    public string Description { get; set; } //(string, null) want to change this to xml type
}

poco 获取方法

   public static List<PlainObj> Get(int InId)
    {
        var s = PetaPoco.Sql.Builder.Append(";EXEC @0", Common.StoreProcs.GetSP);
        s.Append("@@ID = @0", new SqlParameter() { SqlDbType = SqlDbType.Int, Value = InId });

        return PetaPocoContext.Fetch<PlainObj>(s); //Gets the object 
    }

我的问题是,如何获取描述的 XML 而不是字符串,PetaPoco 是否支持它。

最佳答案

我认为 Petapoco 不支持开箱即用的 XML 数据类型,但是如果你在 SQL Server 中将数据类型更改为 XML 并将 poco 上的相应属性保留为字符串,你可以使用类似 linq to xml 的东西或 xDocument 在选择时将返回的字符串作为 xml 处理。您可能还可以向 poco 添加一个 XmlDocument 属性(Petapoco.Igrnored)(我建议在部分类中,这样如果您重新生成 t4,它就不会被覆盖)并处理字符串到 xml 和 xml 到字符串的转换getters/setters,以便您可以无缝访问 XML 对象。虽然我还没有测试对 xml 字段的更新/插入,但 Petapoco 的参数处理通常会接受我扔给它的任何东西。

关于c# - 如何在 PetaPoco 中检索 xml 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28163144/

相关文章:

entity-framework - Entity Framework 6 + SQLite

c++ - 如何与 SQL Server 2008 建立稳定连接并使用 C++ 编写我的第一个 CRUD 操作

c# - 在 List<T> 上使用 Rectangle.Intersection 进行查询

c# - AsNoTracking 方法在 linq 语句中抛出错误

c# - udp 在 .net 中的工作原理

sql - 对于每个更新,在其他地方插入存储过程

c# - C#处理集合中项目的优雅方法

sql-server - 检查 SQL Server 中是否存在触发器的最便携方法是什么?

sql - 如何创建仅获取表中已更新数据的查询

.net - 无法删除 key 。要删除的键已被另一个并发 session 从索引中删除