我正在尝试为Entity Framework实现数据本地化逻辑.因此,如果例如查询选择Title属性,则在幕后它应该引用列Title_enGB或Title_deCH取决于当前用户文化.
为此,我想从Entity Framework重写DbExpression CommandTrees.我以为这些树是建立跨数据库插入/更新/ select查询.但现在所有相关的构造函数/在命名空间中的工厂新的通用.NET的方式System.Data.Metadata和System.Data.Common.CommandTrees在System.Data.Entity.dll都内!(在msdn中公开记录,如:)DbExpressionBuilder.
有没有人有想法实现这个查询操作有或没有查询树重写?
我想要的代码:( public class DbProviderServicesWrapper : DbProviderServices)
/// <summary>
/// Creates a command definition object for the specified provider manifest and command tree.
/// </summary>
/// <param name="providerManifest">Provider manifest previously retrieved from the store provider.</param>
/// <param name="commandTree">Command tree for the statement.</param>
/// <returns>
/// An exectable command definition object.
/// </returns>
protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, …Run Code Online (Sandbox Code Playgroud) c# expression localization expression-trees entity-framework-4
以我个人的编码风格所属Enumerable.OfType<T>().我在任何地方使用它都有点意义.特别是IEnumerable<T>允许强大的linqToObject功能.我讨厌ObjectCollections的"类型不安全"循环,例如下面的示例.现在我有一些关于循环这些"UnGenericCollections"的问题.
ConfigurationSectionCollectionHttpModuleCollectionSPBaseCollectionSPFieldCollectionArrayList问题1:如果我将此转换ArrayList为Enumerable<T>与简单的foreach/if-checks相比有多大的额外循环?
var ark = new ArrayList();
ark.Add(new Human());
ark.Add(new Human());
ark.Add(new Animal());
Run Code Online (Sandbox Code Playgroud)
代替:
foreach (object passenger in ark)
{
if (passanger is Human) { }
if (passanger is Animal) { }
}
Run Code Online (Sandbox Code Playgroud)
我用:
foreach (var human in ark.OfType<Human>())
{
}
foreach (var animal in ark.OfType<Animal>())
{
}
Run Code Online (Sandbox Code Playgroud)
问题2:在foreach循环中使用不同类型的变量时,将使用哪种投射/转换方式?这是一种语言功能还是开箱即用?
foreach (Human human in ark) { }
Run Code Online (Sandbox Code Playgroud)
谢谢你忍受我可怕的英语.最好的问候,本杰明
相信使用委托System.Action或System.Func作为EventDelegates而不是经典的EventHandler模式.因此我会遇到问题吗?
private bool disposed;
public event Action<IUnitOfWork, IContext> Disposing;
public void Dispose()
{
if (this.disposed)
{
return;
}
if (null != this.Disposing)
{
this.Disposing(this, this.AttachedContext);
}
this.disposed = true;
}
Run Code Online (Sandbox Code Playgroud)
-
用法:
unitOfWorkInstance.Disposing += (u, c) => c.Rollback(u); // in my opinion more readable than
unitOfWorkInstance.Disposing += (sender, args) => args.AttachedContext.Rollback(sender as IUnitOfWork);
Run Code Online (Sandbox Code Playgroud)
抱歉可怕的englisch
我们在域模型中使用了自定义LocalizedString类型.我们想用验证属性来装饰属性MaxLength.为此,我们添加了隐式运算符以启用此属性所需的强制转换.
奇怪的是,运算符似乎永远不会被调用,并且在属性IsValid方法中抛出了InvalidCastException .在我们自己的项目中执行此演员表.
在这个系统clr ngen'ed属性中有没有特殊的强制转换行为编译器magix?
// Custom type
public class LocalizedString
{
public string Value
{
get { return string.Empty; }
}
public static implicit operator Array(LocalizedString localizedString)
{
if (localizedString.Value == null)
{
return new char[0];
}
return localizedString.Value.ToCharArray();
}
}
// Type: System.ComponentModel.DataAnnotations.MaxLengthAttribute
// Assembly: System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.ComponentModel.DataAnnotations.dll
public override bool IsValid(object value)
{
this.EnsureLegalLengths();
if (value == null)
{
return true;
}
else
{
string str = value …Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×1
action ×1
expression ×1
foreach ×1
func ×1
generic-list ×1
ienumerable ×1
localization ×1