我有一个WPF客户端,它使用来自WCF服务的DateTime检索数据.
当我把我的电脑放在罗马时间(+1)时,我发现我的结果有些奇怪的行为.
我的WCF方法
public IEnumerable<BookingType> BookingsForFollowingDayReport(DateTime date) {
el = new ErrorLogging();
el.CreateLog(db, new Entities.ErrorType() { DateLogged = DateTime.Now, Type = "DTE", Message = "Report Date: " + date.ToString() });
var a = (from b in db.GetTable<BookingType>()
where b.TourStartDateTime >= date.Date && b.TourStartDateTime <= date.AddDays(1).Date
orderby b.TourStartDateTime
select b);
if (a.Count() > 0) {
el.CreateLog(db, new Entities.ErrorType() { DateLogged = DateTime.Now, Type = "DTE", Message = "Report Date: " + a.FirstOrDefault().TourStartDateTime });
}
return a;
}
Run Code Online (Sandbox Code Playgroud)
该服务在某处的某个Web服务器上联机,现在我从我的WPF客户端调用它.请注意我的方法中的日志记录.
我的电话代码
public static …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个查询,从我加入的数据中获取国家列表.
Places是List<Country>.
var zonedCountries = (from dz in db.DeliveryZones.Include(d => d.Places)
where model.DeliveryZones.Contains(dz.ID)
select dz.Places);
Run Code Online (Sandbox Code Playgroud)
我希望zonedCountries成为一个列表,但它是一个IQueryable<ICollection<Country>>.
如何从中提取列表?
我正在生成一个CSV文件,并尝试使用MVC将其发送到线路,但我一直得到Illegal characters in path异常.
我尝试过使用不同的方法,例如引用列,更改\n Environment.NewLine但是问题的原因仍然无法解决.
控制器代码:
string csv = "";
csv = "Name, Sales, Qty, Cost, Profit" + "\n";
foreach (var item in model.ReportResults.Items) {
csv += item.ToCsv();
}
return File(csv, "text/csv", "myfile.csv");
Run Code Online (Sandbox Code Playgroud)
ToCsv方法:
internal string ToCsv()
{
return "" + Name + "" + "," + Sales.ToString() + "," + Qty.ToString() + "," + Cost.ToString() + "," + Profit.ToString() + "\n";
}
Run Code Online (Sandbox Code Playgroud)
生成的CSV文件的快照:
Name, Sales, Qty, Cost, Profit
Tyranids,4979.29,182,3375.00,1604.29
Space Marines,2127.88,87,948.09,1179.79
Tau Empire,1584.01,40,0.00,1584.01
Eldar,1164.04,44,925.38,238.66
Imperial …Run Code Online (Sandbox Code Playgroud) 我试图通过一个帮助类来过滤 Entity Framework 核心中的一些结果,但我收到了这个错误,我不知道为什么:
NotSupportedException: Could not parse expression 'value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable'1[eVendCustomerDAL.DomainModels.Bin]).Any(__funcTest_0)': The given arguments did not match the expected arguments: Object of type 'System.Linq.Expressions.TypedParameterExpression' cannot be converted to type 'System.Linq.Expressions.LambdaExpression'.
这就是发生错误的地方:
public virtual Revision<DTO> GetStateAsRevision(
Expression<Func<Domain, bool>> query) {
//get all the stateful data from the database
DbSet<Domain> oriSet = db.Set<Domain>();
//query all the data
List<Domain> oriList = oriSet.Where(query).ToList();
Run Code Online (Sandbox Code Playgroud)
该错误似乎是由于query我正在推送的参数而发生的,并且它仅在运行时发生。我不确定是否应该归咎于它的通用性。泛型也是类而不是接口。
where DTO : BaseRevisionDTO
where Domain : BaseTrackedObject
where DomainRevision : BaseRevision
Run Code Online (Sandbox Code Playgroud)
然后我使用以下片段构建表达式:
private Expression<Func<Domain, bool>> GetDomainSearchExpression(Func<Domain, bool> shortFunction) …Run Code Online (Sandbox Code Playgroud) 我在我的Web.config中有这个,所以我的服务将在本地运行:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=IPADD;Initial Catalog=DB;Persist Security Info=True;User ID=UN;Password=PW" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我需要这个,因为Web.Debug.Config不起作用.因此,当我发布时,我想要删除此字符串,因为它实际上是从父Web.config继承的
<connectionStrings>
<remove name="DefaultConnection"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用......(它会引发The entry 'DefaultConnection' has already been added.错误)
我该如何删除它?XSLT?
Ps我无法使用,clear/因为它删除了Machine.Config数据库连接字符串到成员资格提供程序也引发了不同的错误
我有一个模型,以及我需要复制到数据库中的实例列表(大约5000个).
我正在尝试将我的对象同化为数据表,但我不知道该怎么做:
public class BookingType {
public int ID { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int RandomProperty { get; set; }
public int RandomProperty2 { get; set; }
}
public void InsertSomeStuff(IEnumerable<BookingType> bookings) {
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) {
conn.Open();
DataTable dt = new DataTable();
using (SqlBulkCopy copy = new SqlBulkCopy(conn)) {
copy.ColumnMappings.Add(0, 1);
copy.DestinationTableName = "dbo.Bookings";
copy.WriteToServer(dt);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
我需要将其转换为时间跨度:
当我这样做时:
DateTime s = booking.TourStartDate.Add(TimeSpan.Parse(booking.TourStartTime.Replace(".", ":")));
Run Code Online (Sandbox Code Playgroud)
它会在几天之内加上说'10'(上午10点),而不是时间,虽然它是一种愚蠢的格式.