LINQ to Everything-LINQ to XSD增加了更多的LINQiness

It's funny when you work at a company that has as many small projects as it has big ones. I hear one of two things:

当您在一家有很多小项目的公司工作时,这很有趣。 我听到以下两件事之一:

"Is _______ dead? I haven't heard anything in a month from _____ team's blog! It must be dead.

“ _______已经死了吗?一个月内我从未从_____团队的博客上听到任何消息!一定是死了。

or

要么

"Can you just stop with the 99 different ways to do _______? There's more happening that I can handle."

“您能不能仅以99种不同的方式来做_______?我有更多可以应付的事情。”

I'll try to help with the latter in the coming months. Even though we hear about technologies like LINQ to SQL and LINQ to Entities or ASP.NET MVC and WCF and get confused about if they are complementary, there is (usually) a plan behind the whole stack, even if that plan isn't very well-communicated. I'll do a diagram or two to help soon.

在接下来的几个月中,我将尽力为后者提供帮助。 尽管我们听到像LINQ技术,SQL和LINQ到实体或ASP.NET MVC和WCF和弄不清楚,如果他们是相辅相成的,(通常情况下)整个堆栈后面的计划,即使该计划不是很沟通良好。 我会做一两个图表以尽快提供帮助。

But first, looking at the Is ____ dead? question. It'd be cool if someone just dropped a blog post as a "ping" every few weeks like "We're still here! Nope, not dead!" kind of like an Out of Office Response, but for blogs.

但是首先,看看____死了吗? 题。 如果有人每隔几周就以“ ping”的形式发送博客帖子,例如“我们还在这里!不,不是死的!”,这很酷。 有点像外出回应,但用于博客。

For example, LINQ to XSD was mentioned in June of 2007, looked rockin' sweet, and then went silent. However, small teams like this continue to move the ball forward, but we (the outside world) don't hear from them. I'll try to find those projects and ping for the people.

例如,在2007年6月提到了LINQ to XSD ,看上去很甜蜜,然后沉默了。 但是,像这样的小型团队仍在继续前进,但是我们(外界)没有听到他们的消息。 我将尝试找到这些项目并为人们提供便利。

Just yesterday, LINQ to XSD surfaced (I actually had a video call with them on Weds) with a new release.

就在昨天, LINQ to XSD出现了(我实际上在Weds上和他们进行了视频通话)并发布了新版本。

LINQ to XSD creates .NET classes with much better fidelity than what's created with (the aging) XSD.exe. Now, of course, XSD.exe makes classes for XmlSerialization, while LINQ to XSD makes classes that use an XDocument (not XmlDocument) as the backing store, so we are comparing Apples to Carburetors, but if your goal is to get Objects that come from an XML source, you should take a look at LINQ to XSD.

LINQ to XSD创建的.NET类的保真度比使用(老化的)XSD.exe创建的.NET类好得多。 现在,当然,现在XSD.exe为XmlSerialization创建类,而LINQ to XSD为使用XDocument(而不是XmlDocument )作为后备存储的类,因此我们正在将Apple与化油器进行比较,但是如果您的目标是要获得对象,从XML来源,您应该看一下LINQ to XSD。

For example, if I take one of the goofiest schemas, OFX, a financial services schema (disclosure, I was the Vendor Committee Chair for OFX for a few years so I'm to blame a bit) and run it through LinqToXml.exe, here's some differences.

例如,如果我采用一种最愚蠢的模式,即金融服务模式OFX (披露,我曾担任OFX的供应商委员会主席几年,所以我要怪一点),然后通过LinqToXml.exe运行它,这里有些区别。

For example, in the XSD for OFX there's some types like "Amount" that have Restriction Facets. The type is a string, but it must match a certain regular expression, like:

例如,在XSD for OFX中,有些类型具有“限制方面”,例如“金额”。 该类型是字符串,但必须匹配某个正则表达式,例如:

<xsd:simpleType name="AmountType">
    <xsd:restriction base="xsd:string">
        <xsd:maxLength value="32"/>
        <xsd:minLength value="1"/>
        <xsd:whiteSpace value="collapse"/>
        <xsd:pattern value="[\+\-]?[0-9]*(([0-9][,\.]?)|([,\.][0-9]))[0-9]*"/>
    </xsd:restriction>
</xsd:simpleType>

However, when that's turned into generated code via XSD.exe and XmlSerialization, we get:

但是,当通过XSD.exe和XmlSerialization将其转换为生成的代码时,我们得到:

private string amountField
  
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string AMOUNT {   
get {        
return this.amountField;    
}    
set {        
this.amountField = value;    
} }

Which kind of sucks, from a fidelity point of view. We've lost information, the restriction is gone and the Type is gone.

从忠诚的角度来看,哪一种很烂。 我们丢失了信息,限制消失了,类型消失了。

Here's the same thing generated with LINQ to XSD:

这是用LINQ to XSD生成的同一件事:

public sealed class AmountType {     
[DebuggerBrowsable(DebuggerBrowsableState.Never)]    
public static Microsoft.Xml.Schema.Linq.SimpleTypeValidator TypeDefinition =
new Microsoft.Xml.Schema.Linq.AtomicSimpleTypeValidator(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String),
new Microsoft.Xml.Schema.Linq.RestrictionFacets(((Microsoft.Xml.Schema.Linq.RestrictionFlags)(46)), null, 0, 0, null, null, 32, null, null, 1,
new string[] { "^(([\\+\\-]?[0-9]*(([0-9][,\\.]?)|([,\\.][0-9]))[0-9]*))$"}, 0, XmlSchemaWhiteSpace.Collapse));    
private AmountType() {} }

...and...then the accessor:

...然后...访问者:

public string AMOUNT {     
get { XElement x = this.GetElement(XName.Get("AMOUNT", ""));        
return XTypedServices.ParseValue<string>(x, XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).Datatype);     }
    set { this.SetElementWithValidation(XName.Get("AMOUNT", ""), value, "AMOUNT", global::ofx.net.types.Item2003.Item04.AmountType.TypeDefinition);     } }

Note that this is generated, so don't judge it on aesthetics, it's about the experience as a consumer of the API. This is cool because we don't lose anything, the mapping between CLR type and XSD type is clean enough, you get a real type, but you can still access it as a string. If you set a value it's validated on the fly.

请注意,这是生成的,因此不要从美学角度对其进行判断,它是关于API使用者的体验。 这很酷,因为我们不会丢失任何东西,CLR类型和XSD类型之间的映射足够干净,您可以获得真实类型,但仍可以作为字符串访问它。 如果您设置了一个值,它会即时验证。

Remember again, this is an interesting, if biased, comparison as LINQ to XSD uses an XDocument as the backing store and its properties access the DOM, while XSD.exe/XmlSerializer makes copies using dynamically generated temporary helpers and XmlReaders/XmlWriters to make Objects out of your Angle Brackets.

再次记住,这是一个有趣的(如果有偏见的)比较,因为LINQ与XSD使用XDocument作为后备存储,并且其属性访问DOM,而XSD.exe / XmlSerializer使用动态生成的临时帮助程序和XmlReaders / XmlWriters进行复制以创建对象在您的尖括号中。

Another good example of a quiet team that still has cool stuff coming is LINQ to SQL as they update for SQL 2008.

安静的团队中还有很多很棒的东西的另一个很好的例子是LINQ to SQL,因为他们针对SQL 2008进行了更新。

Dear Reader, what's the best way for a team to tell you they are not dead?

亲爱的读者,团队告诉您他们还没有死的最好方法是什么?

Related Posts

相关文章

翻译自: https://www.hanselman.com/blog/linq-to-everything-linq-to-xsd-adds-more-linqiness

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值