今天我使用AutoMapper v1.1升级了一个功能齐全的应用程序,现在使用AutoMapper v2.1,我遇到了一些我以前从未遇到的问题.
这是我的代码映射的示例从后DTO到域对象
public class TypeOne
{
public TypeOne()
{
}
public TypeOne(TypeTwo two)
{
//throw ex if two is null
}
public TypeOne(TypeTwo two, TypeThree three)
{
//throw ex if two or three are null
}
public TypeTwo Two {get; private set;}
public TypeThree Three {get; private set;}
}
public class TypeOneDto
{
public TypeOneDto()
{
}
public TypeTwoDto Two {get; set;}
public TypeThreeDto Three {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
...
Mapper.CreateMap<TypeThreeDto, TypeThree>();
Mapper.CreateMap<TypeTwoDto, TypeTwo>();
Mapper.CreateMap<TypeOneDto, …Run Code Online (Sandbox Code Playgroud) 如何在此查询中打印此查询更新的行:
update
Table1.RecommendationLeg
set
actualValue = ( leg.actualprice * str.currentSize)
from
Table1.RecommendationLeg leg
inner join Recommendation str
on leg.partofId = str.id
where
leg.actualValue = 0
and datediff( n, timeOf, CURRENT_TIMESTAMP) > 30
Run Code Online (Sandbox Code Playgroud) 我一直试图解决这个问题一天,并没有在哪里,所以我希望有人可能已经解决了这个问题.我发现最接近解决方案的是如何使用AutoMapper简单地将NHibernate ISet映射到IList并通过AutoMapper 将IList 映射到ICollection,但仍然没有乐趣.
我有一个看起来像这样的数据对象:
public class Parent
{
public virtual ISet<Child> Children {get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和一个看起来像这样的业务对象:
public class ParentDto
{
public IList<ChildDto> Children {get; set; }
}
Run Code Online (Sandbox Code Playgroud)
使用AutoMapper从Data to Business映射工作正常:
...
Mapper.CreateMap<Parent, ParentDto>();
Mapper.CreateMap<Child, ChildDto>();
...
ParentDto destination = CWMapper.Map<Parent, ParentDto>(source);
Run Code Online (Sandbox Code Playgroud)
但是,当我从业务映射到数据时,我得到错误:
...
Mapper.CreateMap<ParentDto, Parent>();
Mapper.CreateMap<ChildDto, Child>();
...
Parent destination = CWMapper.Map<ParentDto, Parent>(source);
Run Code Online (Sandbox Code Playgroud)
无法将'System.Collections.Generic.List'类型的对象强制转换为''Iesi.Collections.Generic.ISet'
我添加了一个自定义映射:
Mapper.CreateMap<ParentDto, Parent>()
.ForMember(m => m.Children, o => o.MapFrom(s => ToISet<ChildDto>(s.Children)));
private static ISet<T> ToISet<T>(IEnumerable<T> list)
{
Iesi.Collections.Generic.ISet<T> set = …Run Code Online (Sandbox Code Playgroud) 我有多个枚举器枚举平面文件.我最初在并行调用中有每个枚举器,每个Action都添加到a,BlockingCollection<Entity>并且该集合返回一个ConsumingEnumerable();
public interface IFlatFileQuery
{
IEnumerable<Entity> Run();
}
public class FlatFile1 : IFlatFileQuery
{
public IEnumerable<Entity> Run()
{
// loop over a flat file and yield each result
yield return Entity;
}
}
public class Main
{
public IEnumerable<Entity> DoLongTask(ICollection<IFlatFileQuery> _flatFileQueries)
{
// do some other stuff that needs to be returned first:
yield return Entity;
// then enumerate and return the flat file data
foreach (var entity in GetData(_flatFileQueries))
{
yield return entity;
}
}
private IEnumerable<Entity> …Run Code Online (Sandbox Code Playgroud) 我经常遇到这样的情况:我想通过传递一些给定的数据或者另一个对象来创建对象的实例,但数据或对象需要有效或处于正确的状态.我总是对"正确"的做法有点不清楚.这是我的例子:
鉴于此类:
class BusinessObject()
{
const Threshold = 10;
public BusinessObject(SetOfData<SomeType> setofdata)
{
// an example of some validation
if (setofdata.count > Threshold)
{
// performance some business logic
// set properties
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果你这样做可能会遇到一些问题:
var setofdata = new SetOfData<SomeType>();
// if data is not valid then the object will be created incorrectly
var businessObject = new BusinessObject(setofdata);
Run Code Online (Sandbox Code Playgroud)
所以我的解决方案一直是:
class BusinessObjectBuilder()
{
public BusinessObject Build(SetOfData<SomeType> setofdata)
{
// an example of some validation
if (setofdata.count > Threshold)
return new …Run Code Online (Sandbox Code Playgroud) 我正在使用第三方库来迭代一些非常大的平面文件,这可能需要很长时间.该库提供了一个枚举器,因此您可以生成每个结果并对其进行处理,同时枚举器然后提取平面文件中的下一个项目.
例如:
IEnumerable<object> GetItems()
{
var cursor = new Cursor;
try
{
cursor.Open();
while (!cursor.EOF)
{
yield return new //object;
cursor.MoveNext();
}
}
finally
{
if (cursor.IsOpen)
{
cursor.Close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是拥有两个相同Enumerable的消费者,所以我不必两次提取信息,因此每个消费者仍然可以处理每个项目,因为它到达时不必等待所有时间到达一旦.
IEnumerable<object> items = GetItems();
new Thread(SaveToDateBase(items)).Start();
new Thread(SaveSomewhereElse(items)).Start();
Run Code Online (Sandbox Code Playgroud)
我想我想要实现的是类似的东西
"如果消费者要求的项目已被提取,则产生它,否则接下来移动并等待"但我意识到两个线程之间可能存在MoveNext()冲突.
如果没有任何关于如何实现的想法,这样的事情是否已经存在?
谢谢
我写了一些将图像嵌入到页面中的JavaScript.
最终结果在所有浏览器(甚至是IE6和7)上都是成功的,但是对于IE6和7,我收到消息"第15行,第5个字符,未找到成员".这是代码:
09: var url = getUrl();
10: url += 'Impression';
11: url += '?' + getParams();
12: var img = new Image();
13: img.src = url;
14: img.style = "display = 'none';";
15: document.body.insertBefore(img, document.body.firstChild);
Run Code Online (Sandbox Code Playgroud)
要么是document.body.insertBefore或document.body.firstChild不是IE6或7完全支持?
javascript css internet-explorer internet-explorer-7 internet-explorer-6
c# ×5
automapper ×2
automapper-2 ×1
c#-4.0 ×1
css ×1
ienumerable ×1
ienumerator ×1
java ×1
javascript ×1
nhibernate ×1
t-sql ×1