我需要在运行时更改实体的存储架构.我已经关注了一篇很棒的帖子,可以在这里找到:http: //blogs.microsoft.co.il/blogs/idof/archive/2008/08/22/change-entity-framework-storage-db-schema-in-runtime的.aspx?CommentPosted =真#commentmessage
这非常有效,但仅适用于查询,不适用于修改.
知道为什么吗?
我需要创建以下XML,我正在尝试使用XDocument.但是,我在指定名称空间时遇到了麻烦.
<AssessmentOrderRequest
xsi:schemaLocation="http://ns.hr-xml.org/2007-04-15 http://ns.hr-xml.org/2_5/HR-XML-2_5/StandAlone/AssessmentOrderRequest.xsd"
xmlns="http://ns.hr-xml.org/2007-04-15"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</AssessmentOrderRequest>
Run Code Online (Sandbox Code Playgroud)
这是我正在寻找的那种代码,但是,我无法在名称中创建带冒号的属性xsi:schemaLocation
.
return new XDocument(
new XElement("AssessmentOrderRequest",
new XAttribute("xsi:schemaLocation", XNamespace.Get("http://ns.hr-xml.org/2007-04-15 http://ns.hr-xml.org/2_5/HR-XML-2_5/StandAlone/AssessmentOrderRequest.xsd")),
new XAttribute("xmlns", XNamespace.Get("http://ns.hr-xml.org/2007-04-15")),
new XAttribute(XNamespace.Xmlns + "xsi", XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"))
)
);
Run Code Online (Sandbox Code Playgroud) 我有一个代码,它将读取一些xml文件.我尝试了不同的方法来解决这个问题,但不能.我也尝试这样编码:
Namespace my = "http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30";
XElement myEgitimBilgileri = XDocument.Load(@"C:\25036077.xml").Element("my:"+ "Egitim_Bilgileri");
Run Code Online (Sandbox Code Playgroud)
但一直都是同样的错误.这是原作:
private void button2_Click(object sender, EventArgs e)
{
XElement myEgitimBilgileri =
XDocument.Load(@"C:\25036077.xml").Element("my:Egitim_Bilgileri");
if (myEgitimBilgileri != null)
{
foreach (XElement element in myEgitimBilgileri.Elements())
{
Console.WriteLine("Name: {0}\tValue: {1}", element.Name, element.Value.Trim());
}
}
Console.Read();
}
Run Code Online (Sandbox Code Playgroud)
这是我的xml文件的路径:
<my:Egitim_Bilgileri>
<my:egitimler_sap>
<my:sap_eduname></my:sap_eduname>
<my:sap_edufaculty></my:sap_edufaculty>
<my:sap_eduprofession></my:sap_eduprofession>
<my:sap_diplomno></my:sap_diplomno>
<my:sap_edulevel></my:sap_edulevel>
<my:sap_edustartdate xsi:nil="true"></my:sap_edustartdate>
<my:sap_eduenddate xsi:nil="true"></my:sap_eduenddate>
</my:egitimler_sap>
</my:Egitim_Bilgileri>
Run Code Online (Sandbox Code Playgroud)
这是我在XML中的命名空间的路径
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-01-11T08:31:30"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-01-23T00:43:17"
Run Code Online (Sandbox Code Playgroud) 我正在使用 VS2010、C#、.net 和 xmlWriter 创建符合 HL7 CAT-1 规范的 xml 文档。必须在文档中创建一个属性“sdtc:ValueSet”。由于字符“:”无效,我无法写入此属性名称。
这是实际的代码行:
writer.WriteAttributeString("sdtc:valueSet", "OID value");
Run Code Online (Sandbox Code Playgroud)
有没有人有创建属性的解决方案,如图所示?
继续研究,但决定发布这个问题,希望快速找到解决方案。
这个问题被标记为重复,我在争论是错误的。现有响应引用了编写元素或使用 LINQ。该问题使用 xmlWriter 明确说明了 Attribute。一位响应者建议使用重载的 WriteAttributeString 方法,该方法解决了问题。