我想为我的edmx-model中的每个实体创建一个名为{0} Validator.cs的独立类文件(现在不关心它的内容).
这似乎有效,但我无法解决阻止我的T4模板首先删除我的所有文件.我怎样才能摆脱这种行为?
我发现如果我调用fileManager.Process(true),我的validator.tt文件下的所有文件都将被重新创建(我不想这样).
有什么想法吗?谢谢!
<#@ template language="C#" debug="false" hostspecific="true"#>
//<#@ include file="EF.Utility.CS.ttinclude"#>
<#@output extension=".cs"#>
<#
CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
string inputFile =@"ServicesEntities.edmx";
EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion();
EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);
// for test purposes only...
fileManager.Process(true);
// for each entity, create a xxxValidator.cs file
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{
string fileName = entity.Name + "Validator.cs";
string filePath = this.Host.TemplateFile.Substring(0,this.Host.TemplateFile.LastIndexOf(@"\"));
filePath …
Run Code Online (Sandbox Code Playgroud) 我们通过WCF从客户端(Silverlight)接收文件,在服务器端我解析此文件.文件中的每一行都转换为一个对象并存储到数据库中.如果文件非常大(10000个条目和更多),我收到以下错误(MSSQLEXPRESS):
与当前连接关联的事务已完成但尚未处理.必须先处理事务,然后才能使用连接执行SQL语句.
我尝试了很多(TransactionOptions超时设置等),但没有用.上面的异常消息是在3000之后引发的,有时是在处理了6000个对象之后引发的,但是我无法成功处理所有对象.
我追加了我的来源,希望有人有个主意,可以帮助我:
public xxxResponse SendLogFile (xxxRequest request
{
const int INTERMEDIATE_SAVE = 100;
using (var context = new EntityFramework.Models.Cubes_ServicesEntities())
{
// start a new transactionscope with the timeout of 0 (unlimited time for developing purposes)
using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew,
new TransactionOptions
{
IsolationLevel = System.Transactions.IsolationLevel.Serializable,
Timeout = TimeSpan.FromSeconds(0)
}))
{
try
{
// open the connection manually to prevent undesired close of DB
// (MSDTC)
context.Connection.Open();
int timeout = context.Connection.ConnectionTimeout;
int Counter = 0;
// read …
Run Code Online (Sandbox Code Playgroud)