petapoco模板修改

[Reference(ReferenceType.Many, ColumnName = "OneId", ReferenceMemberName = "OneId")]

var user = Database.FetchOneToMany<UserDecoratedWithExtraInfoAsList>(
x => x.ExtraUserInfo,
x => x.UserId,
"select u.*, e.* from users u left join extrauserinfos e on u.userid = e.userId where u.userid = 1").Single();

 

[ResultColumn, Reference(ReferenceType.Many)]
public List<ExtraUserInfoDecorated> ExtraUserInfo { get; set; }

Right click .tt file and then "Debug T4 Template"

 

https://stackoverflow.com/questions/41000524/visual-studio-serialization-error-when-t4-uses-dte-to-open-generated-file

GetService改为GetCOMService

IServiceProvider.GetService(typeof(DTE)) returns a Proxy Object. Proxy objects work by serializing data across app domains. You can confirm dte is a "transparent proxy" like this:

bool isProxy = RemotingServices.IsTransparentProxy(dte);

The EnvDTE assemblies are COM interop assemblies. Your error can be avoided by creating a Runtime Callable Wrapper, which can intelligently marshal calls to the COM object based off information in the interop-assembly. Microsoft has provided an extension method within theMicrosoft.VisualStudio.TextTemplating namespace:

<#@ template hostspecific="true" language="C#" #> <#@ assembly name="EnvDTE" #> <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #> <# IServiceProvider serviceProvider = (IServiceProvider)this.Host; EnvDTE.DTE dte = (EnvDTE.DTE) serviceProvider.GetCOMService(typeof(EnvDTE.DTE)); #>

The GetCOMService(this IServiceProvider, Type type) extension method is the correct way to obtain the dte COM object. I'm not aware of the absolute specifics, but the RCW alters how the method calls between your code and the COM object get serialized into a data stream.

T4 templates run in a separate AppDomain, and I believe that is the reason your code is working despite the exception.

 

https://blog.csdn.net/weixin_42930928/article/details/89513174

转载于:https://www.cnblogs.com/zwei1121/p/10245258.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值