我想知道是否可以在保存其他文件时运行T4模板,例如在保存xml文件后运行我的.tt文件
我忘了提到我的IDE是VS2010
有没有人知道是否有可能从VS2010内的另一个T4模板运行T4模板文件
谢谢
我在C#.NET中开发了一个使用Excel Interop的控制台程序.如果我从命令行运行它,该程序在我的开发机器和Windows Server 2008中运行正常.
当我尝试安排每天运行它的任务时,我得到了令人讨厌的Interop错误:
02/11/2011 00:30:05,000 [1] FATAL My.Program [(null)] - Unable to Microsoft Office Excel open file 'E:\excel.xls' by one of several reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as the currently opened book.
System.Runtime.InteropServices.COMException (0x800A03EC): Unable to access the Microsoft Office Excel file 'E:\excel.xls' by one of several reasons:
• The file name …Run Code Online (Sandbox Code Playgroud) 当我尝试验证对象是否已经在Entity Framework上下文中时,我在使用EF4时遇到了问题.
我在下面有这个代码
var entityName = Entity4Test + Guid.NewGuid();
using( var ctx = new EnviroDataContext() )
{
var etc = new Entity
{
Name = entityName
};
ctx.Entity.AddObject( etc );
var q = from p in ctx.Entity
where p.Name == entityName
select p;
// Why 'q.ToList().Count == 0'?
ctx.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么插入后我的搜索出来了?
我知道数据在'SaveChanges'之后仍然存在,但如果我需要'查询'我的实体内存数据该怎么办.
扩展问题
我有一个业务规则,通过添加1个项目A,触发其他实体B的插入.问题是,我有验证规则,在插入B时,t A必须已经存在.
因为所有这些操作都是在"SaveChanges"之前进行的,所以我收到EntityA不存在的错误.
其他情况下,我有一个在表上唯一的名称字段.如果我尝试运行AddEntityName("bla")两次然后运行'SaveChanges',我会从DB [Unique constraints]中获得异常,即使在通过我的验证插入之后,也保证名称是唯一的.
任何人都有任何想法?
我正在尝试关注有关XML序列化的微软教程,但是我遇到了一些问题!
这是XML文件,用作输入:
<?xml version="1.0" encoding="utf-8"?>
<Books xmlns:books="http://www.cpandl.com" xmlns:money="http://www.cohowinery.com">
<money:Book>
<books:TITLE>A Book Title</books:TITLE>
<money:PRICE books:currency="US Dollar">
<money:price>9.95</money:price>
</money:PRICE>
</money:Book>
</Books>
Run Code Online (Sandbox Code Playgroud)
这是绑定XML的类:
public class OrderedItem
{
[XmlElement(Namespace = "http://www.cpandl.com")]
public string ItemName;
[XmlElement(Namespace = "http://www.cpandl.com")]
public string Description;
[XmlElement(Namespace = "http://www.cohowinery.com")]
public decimal UnitPrice;
[XmlElement(Namespace = "http://www.cpandl.com")]
public int Quantity;
[XmlElement(Namespace = "http://www.cohowinery.com")]
public decimal LineTotal;
// A custom method used to calculate price per item.
public void Calculate()
{
LineTotal = UnitPrice * Quantity;
}
}
Run Code Online (Sandbox Code Playgroud)
该函数将XML读入'OrderedItem'类:
Console.WriteLine("Reading with …Run Code Online (Sandbox Code Playgroud) 我正在使用SpecFlow和Nunit,我正在尝试使用TestFixtureSetUpAttribute设置我的环境测试,但它从未被调用过.
我已经尝试过使用MSTests和ClassInitialize属性,但同样的事情发生了.该函数未被调用.
任何想法为什么?
[Binding]
public class UsersCRUDSteps
{
[NUnit.Framework.TestFixtureSetUpAttribute()]
public virtual void TestInitialize()
{
// THIS FUNCTION IS NEVER CALLER
ObjectFactory.Initialize(x =>
{
x.For<IDateTimeService>().Use<DateTimeService>();
});
throw new Exception("BBB");
}
private string username, password;
[Given(@"I have entered username ""(.*)"" and password ""(.*)""")]
public void GivenIHaveEnteredUsernameAndPassword(string username, string password)
{
this.username = username;
this.password = password;
}
[When(@"I press register")]
public void WhenIPressRegister()
{
}
[Then(@"the result should be default account created")]
public void ThenTheResultShouldBeDefaultAccountCreated()
{
}
Run Code Online (Sandbox Code Playgroud)
解:
[Binding]
public class UsersCRUDSteps …Run Code Online (Sandbox Code Playgroud) 我正在尝试将动态内容添加到我的mvc应用程序中.
我正在使用Steven Sanderson发布编辑可变长度列表,ASP.NET MVC 2样式,并且由于它,我有一些动态内容.由于我的应用程序的一些限制,我不得不改变基础礼品类.
问题是现在应用程序无法正常工作.
在我的模型中我有:
public class Gift
{
//public string Name { get; set; }
//public double Price { get; set; }
public List<string> MyList { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在,我在gifts参数中得到null值
[HttpPost]
public ActionResult Index(IEnumerable<Gift> gifts)
{
return View("Completed", gifts);
}
Run Code Online (Sandbox Code Playgroud)
谁可以帮我这个事?
编辑: 这是我的查看代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Enviro2011.Models.Gift>>" %>
<asp:Content ContentPlaceHolderID="HeadContent" runat="server">
<link rel="Stylesheet" href="../../Content/styles.css" />
<script type="text/javascript">
$(document).ready(function () {
$("#addItem").click(function () {
$.ajax({
url: this.href,
cache: false,
success: function (html) { …Run Code Online (Sandbox Code Playgroud) .net ×2
t4 ×2
asp.net-mvc ×1
c# ×1
jquery ×1
nunit ×1
specflow ×1
structuremap ×1
templates ×1
xml ×1