小编cuo*_*gle的帖子

多个包括使用实体框架和存储库模式

我正在使用实体框架和存储库模式来进行所有数据访问,当使用表格导航时,我注意到当我获得第一个对象并引用导航对象中的字段时,正在运行2个查询.因为我在数据库中有很多关系,使用这种技术导航属性可能会导致性能开销.

我已经研究了这个Include(string tableName)方法,这将非常有效(如果我没有使用通用RP),但这只需要一个表名.我已成功地复制这个在我的仓库模式的一个包括通过改变我从那里classsEntityObject,但我怎么可以有多个包含在一个查询中使用一个仓库模式?

这是我的代码:

public class GenericRepository<T> : IRepository<T> where T : EntityObject, new()
{
    private Entities _Context;
    private ObjectSet<T> _ObjectSet;

    public IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate, string include)
    {
        // This works OK
        return this._ObjectSet.Include(include).Where(predicate);
    }

    public IQueryable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate, param string[] include)
    {
        // This will not work but is what I am trying to do
        return this._ObjectSet.Include(include).Where(predicate);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# generics entity-framework repository-pattern

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

DataTable to Dictionary <string,Dictionary <string,string >>

我的DataTable包含17列,其中我正在检索3列.对于Instance,我们将这3列视为colA,colB,colC.我的要求是,结果应该是格式

Dictionary<string, Dictionary<string,string>> ( Dictionary<colA,Dictionary<colB,colC>> )
Run Code Online (Sandbox Code Playgroud)

使用LINQ会更好......!

Dictionary<string, Dictionary<string, string>> roles = TA_Roles.GetRoleByUsername(Username)
    .Select(col => new { col.RoleID, col.Rolecode, col.Rolename }) 
    //Please continue from here..!
Run Code Online (Sandbox Code Playgroud)

c# linq dataset

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

Reflection从所有其他派生类中排除基类的所有属性和特定属性

我有以下基础,中间和派生类::

public class Base
{
    [DataMemberAttribute()]
    public int ValueBase { get; set; }

    [IgnoreForAllAttribute("Param1", "Param2")]
    public int IgnoreBase { get; set; }
}

public class Middle : Base
{
    [DataMemberAttribute()]
    public int ValueMiddle { get; set; }

    [IgnoreForAllAttribute("Param1", "Param2")]
    public int IgnoreMiddle { get; set; }
}

public class MostDerived : Middle
{
    [DataMemberAttribute()]
    public int ValueMostDerived { get; set; }

    [IgnoreForAllAttribute("Param1", "Param2")]
    public int IgnoreMostDerived { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我需要一个给定类型的函数,我需要为层次结构中除基础之外的所有类返回DataMemberAttribute属性.

此外,应该忽略图中所有类的所有IgnoreForAllAttribute属性.

var derivedObject = new MostDerived();
var attributes …
Run Code Online (Sandbox Code Playgroud)

.net c# system.reflection

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

如何在不知道何时完成的情况下显示进程

当我有一个我知道它何时完成的过程时,我会使用进度条.但我可以用什么来表明一个过程正在进行但我不知道什么时候会结束?

在WPF中是否有任何特殊控制?

c# wpf wpf-controls

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

从日期列获取按月过滤的行

我有一个数据表,其中记录的日期字段列的值为

11/1/2012
12/21/2012
12/22/2012
1/3/2013
1/5/2013
1/6/2013
1/7/2013
etc. 
Run Code Online (Sandbox Code Playgroud)

我想过滤记录并仅获取当前月份记录,即仅获取日期等于当前月份的行(将由DateTime.now查找).我们怎样才能用Linq和c#做到这一点.

c# linq date

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

为什么IList <T>再次继承IEnumerable <T>和IEnumerable

我已经采取了外观上IList<T>ICollection<T>MSDN上的机会,看到这两个接口的定义是:

public interface ICollection<T> : IEnumerable<T>, IEnumerable
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
Run Code Online (Sandbox Code Playgroud)

请注意,ICollection<T>继承自IEnumerable<T>IEnumerable,没关系.IList<T>继承ICollection<T>,但为什么IList<T>要继承IEnumerable<T>IEnumerable再次?

有什么理由吗?

.net c# generics ienumerable

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

操纵字符串

我试图从字符串中删除一些特殊字符.我有以下字符串

[_fesd][009] Statement
Run Code Online (Sandbox Code Playgroud)

我想摆脱所有'_''['和']'我设法删除TrimStart的第一个字符,我得到了fesd] [009]声明

我该如何从字符串中间删除特殊字符?

目前我正在使用以下代码

string newStr = str.Trim(new Char[] { '[', ']', '_' });
Run Code Online (Sandbox Code Playgroud)

其中str是应该进行操作的strin,结果应该存储在newStr中

c#

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

JavaScript范围和提升:代码按预期返回1而不是10

我是JavaScript的新手,我真的不太明白为什么下面的代码返回1而不是10:

var a = 1;
function b() {
    a = 10;
    return;
    function a() {}
}
b();
alert(a);
Run Code Online (Sandbox Code Playgroud)

运行代码:http://jsfiddle.net/smMtU/

如果我撤消该行function a() {},它将10按预期返回.这段代码来自这篇文章,解释了JavaScript中的概念范围和提升.也许我在阅读这篇文章时遗漏了一些东西?

请有人指出这段代码背后的概念吗?

javascript

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

如何在Go中获取命令参数?

我刚开始学习Go,并且我使用该ProbablyPrime库编写了一个主要的测试程序.

package main

import (
    "fmt"
    "math/big"
    "math"
    "os"
    "strconv"
)

func prime_test(n int64, certainty int)(bool,float64){
    var probobility float64
    i := big.NewInt(n)
    isPrime := i.ProbablyPrime(certainty)
    probobility = 1 - 1/math.Pow(4,10)
    return isPrime, probobility
}

func why_not_prime(n int64)(int64){
    var i int64 
    for  i=2 ; i<n/2; i++ {
        if n%i == 0 {return i}
    }
    return i
}


func main() {
    var n int64
    var certainty int
    var isPrime bool
    var probobility float64 

    if len(os.Args) > 1 {
    n,_ = …
Run Code Online (Sandbox Code Playgroud)

go command-line-arguments

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

通用代表

我想拥有一个方法的委托,该方法接受一个参数并返回相同类型的结果.我也希望类型由泛型类型参数确定,但以下语法使我失望.

delegate T SomeDelegate(T param)<T>;
Run Code Online (Sandbox Code Playgroud)

我怎么能实现这个目标?

c# generics

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