Using the named simple types with LINQ to XSD results in a compiler error

I have an XSD containing a simple type:

<xs:simpleType name="csharpName" id="csharpName">
    <xs:restriction base="xs:string">
        <xs:pattern value="[A-Za-z][A-Za-z0-9_]*" />
    </xs:restriction>
</xs:simpleType>

Now when I use this type:

 <xs:element name="typeName" type="csharpName" />

LINQ to XSD generates

this.SetElementWithValidation(XName.Get("typeName", ""), value, "typeName", global::.csharpName.TypeDefinition);`

Pay attention to ::. after global. Now this point is very wrong, I assume that I am missing a namespace. Now, if I delete the point manually, it works fine, but I would prefer not to delete dozens or so in each generation. Do you have any ideas?

+3
source share
3 answers

Ok, here is the right correct answer! (I am using the nuget Linq2Xsd package )

, , XSD, , XML , , .

  • targetNamespace, , , .
  • LINQ-TO-XSD-CONFIG.xsd . .
  • LinqToXsdConfiguration
  • NB: , , .

enter image description here

Clr. , DLL \obj\Debug\LinqToXsdSource.cs, XSD, .

, . ::.

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="http://www.microsoft.com/xml/schema/linq">
  <Namespaces>
    <Namespace Schema="http://example.com/idr" Clr="example.com.idr"/>
    <Namespace Schema="" Clr="LinqXsdGenericNamespace"/>
  </Namespaces>
</Configuration>

: http://linqtoxsd.codeplex.com/discussions/238570

+2

, , :

<xs:schema
    attributeFormDefault="unqualified"
    elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://codegen"
    xmlns:codegen="http://codegen">

codegen.

+3

, :

  • @TDaver , , ::. . , Custom Tool Namespace, . Amazon XSD, , , , XSD .

  • Linq2XSD , - - , nuget, DLL, , .

  • : XSD single LinqToXsdSource.cs. , XSD, .

  • You may need to monitor the obj \ Debug folder that contains the file LinqToXsdSource.cs. You can simply throw this folder away if you have problems, or just keep it open for error tracking.

+2
source

Source: https://habr.com/ru/post/1785451/


All Articles