(早期的问题,递归(?)将LINQ谓词组合成单个谓词,与此类似但我实际上问了错误的问题......那里的解决方案满足了提出的问题,但实际上并不是我需要的问题.虽然不一样.诚实.)
鉴于以下搜索文本:
"keyword1 keyword2 ... keywordN"
Run Code Online (Sandbox Code Playgroud)
我想最终得到以下SQL:
SELECT [columns] FROM Customer
WHERE (
Customer.Forenames LIKE '%keyword1%'
OR
Customer.Forenames LIKE '%keyword2%'
OR
...
OR
Customer.Forenames LIKE '%keywordN%'
) AND (
Customer.Surname LIKE '%keyword1%'
OR
Customer.Surname LIKE '%keyword2%'
OR
....
OR
Customer.Surname LIKE '%keywordN%'
)
Run Code Online (Sandbox Code Playgroud)
实际上,我们将搜索文本拆分为空格,修剪每个标记,根据每个标记构造一个多部分OR子句,然后将这些子句一起进行AND运算.
我在Linq-to-SQL中这样做,我不知道如何根据任意长的子预测列表动态编写谓词.对于已知数量的子句,可以轻松地手动编写谓词:
dataContext.Customers.Where(
(
Customer.Forenames.Contains("keyword1")
||
Customer.Forenames.Contains("keyword2")
) && (
Customer.Surname.Contains("keyword1")
||
Customer.Surname.Contains("keyword2")
)
);
Run Code Online (Sandbox Code Playgroud)
简而言之,我需要一种技术,给定两个谓词,将返回使用提供的运算符组成两个源谓词的单个谓词,但仅限于Linq-to-SQL明确支持的运算符.有任何想法吗?
我想在运行时动态地将MEF Export属性应用于某个类型,就好像该类型在编译时应用了Export属性一样.
有一个简单的方法吗?
除此之外,是否有一种复杂的方法可以做到这一点?
在设计类图时,我很难理解这些,从我所知的构成是一个"有一个"的关系但聚合?我不知道它是什么.还有一件事我什么时候才能在类图中使用Composition?什么时候才能知道在类图中使用聚合?一个例子将受到高度赞赏.
我有一个AggregateCatalog,其中包含AssemblyCatalog和DirectoryCatalog.
我希望他们像这样工作:
我怎样才能实现这样的目标?
我有一个MEF应用程序,在本地运行时效果很好,但在网络共享上远程调用时不起作用.
我正在使用Assembly.LoadFrom来避免UNC问题,但看到所有的dll都位于exe旁边,我并不认为这会是问题所在,但我尝试了任何方式.
在查看msdn之后,我还修复了ConfigurationManager.GetSection问题,这似乎是.NET 4权限的常见问题.
我<loadFromRemoteSources enabled="true"/>在配置文件中允许.所以我不确定问题出在哪里.
编辑:例外中的ProductDispatcher在catalog.Parts中是明确的.
设置容器和目录的代码:
var catalog = new AggregateCatalog();
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
foreach (string file in Directory.GetFiles(dir, "XXX*.dll"))
{
var assembly = Assembly.LoadFrom(file);
catalog.Catalogs.Add(new AssemblyCatalog(assembly));
}
var container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddPart(this);
container.Compose(batch);
Run Code Online (Sandbox Code Playgroud)
导入是(我试过公开):
[ImportMany(typeof(IEntityTypeDispatcher))]
private IEnumerable<IEntityTypeDispatcher> Dispatchers { get; set; }
Run Code Online (Sandbox Code Playgroud)
导出的一个例子是:
[Export(typeof(IEntityTypeDispatcher))]
internal class ContactDispatcher : EntityTypeDispatcher<Contact>
Run Code Online (Sandbox Code Playgroud)
我得到的异常错误是:
The composition produced a single composition error. The root cause is provided below. Review the …Run Code Online (Sandbox Code Playgroud) 我正在处理这个问题.我正在创造数学问题,每个人都有回应.例如.
我的大问题是.
如何在类问题和响应之间建立关系.如果这应该是一个关联,聚合或组合,我也在处理.
谢谢.
编辑:很好,这是一个组合.最后,根据上述句子,我该如何表现设计?这些是我的一些想法,但我想我错了.
public class Question
{
public Response _response;
//public List<Response>
//public Dictionary<string, Response>
public Question()
{
this._response = new Response();
}
}
public class Response
{
}
Run Code Online (Sandbox Code Playgroud) 我想知道我是否可以按照我的方式建模下面两个类层次结构之间的关系:

代表其含义的代码如下:
public abstract class Car
{
protected Engine engine;
}
public class StreetCar extends Car
{
public StreetCar()
{
engine = new StreetEngine();
}
}
Run Code Online (Sandbox Code Playgroud)
......类似于OffroadCar类,它会做类似的事情engine = new OffroadEngine().我没有包含有关accele()方法的任何内容,它没有关系.
我只是想知道组合是否正确建模,或者添加那么多组合箭头是多余的甚至是错误的.
问题: 如何使用Triangle Class扩展Point(超(?))并组成一个如下所示的对象:
// "name":"Thomas The Triangle",
// "points": [
// {age: "2015-05-28T06:23:26.160Z", x: 1, y: 1 },
// {age: "2015-05-28T06:23:26.161Z", x: 0, y: 3 },
// {age: "2015-05-28T06:23:26.164Z", x: 2, y: 3 }
// ]
Run Code Online (Sandbox Code Playgroud)
JS:
class Point {
constructor(x, y){
this.name = "Point"
this.age = new Date();
this.x = x;
this.y = y;
}
}
class Triangle extends Point{
constructor(coords, name) {
super(coords[0][0], coords[0][1]); //this line is best I could do but not correct
this.name = name
} …Run Code Online (Sandbox Code Playgroud) 假设我有两个monad变换器
T1 :: (* -> *) -> * -> *
T2 :: (* -> *) -> * -> *
Run Code Online (Sandbox Code Playgroud)
与实例
instance MonadTrans T1
instance MonadTrans T2
Run Code Online (Sandbox Code Playgroud)
还有一些
X :: (((* -> *) -> * -> *) -> ((* -> *) -> * -> *) -> * -> *)
Run Code Online (Sandbox Code Playgroud)
如
newtype X t1 t2 a b = X { x :: t1 (t2 a) b }
Run Code Online (Sandbox Code Playgroud)
我想为此定义一些东西
instance (MonadTrans t1, MonadTrans t2) => MonadTrans (X t1 t2) where
lift = X …Run Code Online (Sandbox Code Playgroud) class Book {
private Chapter[] chapters = new Chapter[5];
}
class Chapter {
private Book book;
}
Run Code Online (Sandbox Code Playgroud)
这是实现上述关系的正确方法吗?我需要对此进行解释.谢谢.
composition ×10
.net ×3
c# ×3
mef ×3
aggregation ×2
java ×2
uml ×2
class ×1
haskell ×1
inheritance ×1
javascript ×1
linq ×1
linq-to-sql ×1
modeling ×1
monads ×1
oop ×1
relationship ×1