小编Har*_*ryK的帖子

防止T4模板删除现有文件

我想为我的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)

t4 entity-framework

6
推荐指数
2
解决办法
4211
查看次数

使用EntityFramework 4.0进行批量插入会导致事务中止

我们通过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)

entity-framework transactions

1
推荐指数
1
解决办法
6695
查看次数

标签 统计

entity-framework ×2

t4 ×1

transactions ×1