我正在使用实体框架和存储库模式来进行所有数据访问,当使用表格导航时,我注意到当我获得第一个对象并引用导航对象中的字段时,正在运行2个查询.因为我在数据库中有很多关系,使用这种技术导航属性可能会导致性能开销.
我已经研究了这个Include(string tableName)方法,这将非常有效(如果我没有使用通用RP),但这只需要一个表名.我已成功地复制这个在我的仓库模式的一个包括通过改变我从那里classs来EntityObject,但我怎么可以有多个包含在一个查询中使用一个仓库模式?
这是我的代码:
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) 我的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) 我有以下基础,中间和派生类::
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) 当我有一个我知道它何时完成的过程时,我会使用进度条.但我可以用什么来表明一个过程正在进行但我不知道什么时候会结束?
在WPF中是否有任何特殊控制?
我有一个数据表,其中记录的日期字段列的值为
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#做到这一点.
我已经采取了外观上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再次?
有什么理由吗?
我试图从字符串中删除一些特殊字符.我有以下字符串
[_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中
我是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中的概念范围和提升.也许我在阅读这篇文章时遗漏了一些东西?
请有人指出这段代码背后的概念吗?
我刚开始学习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) 我想拥有一个方法的委托,该方法接受一个参数并返回相同类型的结果.我也希望类型由泛型类型参数确定,但以下语法使我失望.
delegate T SomeDelegate(T param)<T>;
Run Code Online (Sandbox Code Playgroud)
我怎么能实现这个目标?
c# ×8
generics ×3
.net ×2
linq ×2
dataset ×1
date ×1
go ×1
ienumerable ×1
javascript ×1
wpf ×1
wpf-controls ×1