尝试执行linq查询时出现以下错误:
LINQ to Entities无法识别方法'Boolean IsCharityMatching(System.String,System.String)'方法,并且此方法无法转换为商店表达式.
我已经阅读了很多以前的问题,人们会得到相同的错误,如果我理解正确,那是因为LINQ to Entities需要将整个linq查询表达式转换为服务器查询,因此你不能调用外部方法在里面.我无法将我的场景转换成有效的东西,我的大脑开始融化,所以我希望有人能指出我正确的方向.我们正在使用实体框架和规范模式(我对两者都是新手).
这是使用规范的代码:
ISpecification<Charity> specification = new CharitySearchSpecification(charityTitle, charityReference);
charities = charitiesRepository.Find(specification).OrderBy(p => p.RegisteredName).ToList();
Run Code Online (Sandbox Code Playgroud)
这是linq表达式:
public System.Linq.Expressions.Expression<Func<Charity, bool>> IsSatisfied()
{
return p => p.IsCharityMatching(this.charityName, this.charityReference);
}
Run Code Online (Sandbox Code Playgroud)
这是IsCharityMatching方法:
public bool IsCharityMatching(string name, string referenceNumber)
{
bool exists = true;
if (!String.IsNullOrEmpty(name))
{
if (!this.registeredName.ToLower().Contains(name.ToLower()) &&
!this.alias.ToLower().Contains(name.ToLower()) &&
!this.charityId.ToLower().Contains(name.ToLower()))
{
exists = false;
}
}
if (!String.IsNullOrEmpty(referenceNumber))
{
if (!this.charityReference.ToLower().Contains(referenceNumber.ToLower()))
{
exists = false;
}
}
return exists;
}
Run Code Online (Sandbox Code Playgroud)
如果您需要更多信息,请与我们联系.
非常感谢,
Annelie
.net linq linq-to-entities entity-framework specification-pattern
我正在尝试部署Windows服务但不太确定如何正确执行.我将它构建为控制台应用程序,我现在将其转换为Windows服务项目,并从服务中的OnStart方法调用我的类.
我现在需要在没有Visual Studio的服务器上安装它,如果我正确理解它意味着我不能使用InstallUtil.exe而必须创建一个安装程序类.它是否正确?
我确实看过上一个问题,安装没有InstallUtil.exe的.NET Windows服务,但我只是想确保我已经正确理解它.
如果我创建了问题的接受答案链接到的类,下一步是什么?将MyService.exe和MyService.exe.config上传到服务器,双击exe文件,Bob是我的叔叔?
该服务只能安装在一台服务器上.
我是线程新手,想做类似这个问题的事情:
但是,我不确定这个解决方案是否对我来说是最好的,因为我希望它们继续运行并且永远不会完成.(对于那个问题,我也使用.net 3.5而不是2.0.)
我想做这样的事情:
foreach (Agent agent in AgentList)
{
// I want to start a new thread for each of these
agent.DoProcessLoop();
}
---
public void DoProcessLoop()
{
while (true)
{
// do the processing
// this is things like check folder for new files, update database
// if new files found
}
}
Run Code Online (Sandbox Code Playgroud)
ThreadPool是最好的解决方案还是有更适合这种情况的东西?
更新:感谢所有的好答案!我以为我会更详细地解释用例.许多代理可以将文件上载到文件夹.每个代理都有自己的文件夹,可以将资源上传到(csv文件,图像,pdf).我们的服务(它意味着是在他们上传资产的服务器上运行的Windows服务,请放心,我将很快回来关于Windows服务的问题:))如果有任何新资产,将继续检查每个代理的文件夹,如果有,数据库将被更新,并为其中一些创建静态html页面.因为他们可能需要一段时间来上传所有内容,我们希望他们能够立即看到他们上传的更改,我们认为每个代理的线程都是个好主意,因为没有代理人需要等待其他人来完成(我们有多个处理器,所以想要使用它们的全部容量).希望这能解释它!
谢谢,
Annelie
我想知道在发送文本之前解析和验证手机号码的最佳做法是什么.我已经有了可行的代码,但我想找到更好的方法(我的最后一个问题,这是我早期新年决议中编写质量更好的代码的一部分!).
当用户输入表格上的号码时,我们非常宽容,他们可以输入"+44 123 4567890","00441234567890","0123456789","+ 44(0)123456789","012-345"等内容. -6789"甚至"没有电话".
但是,要发送文本格式必须是44xxxxxxxxxx(这仅适用于英国手机),因此我们需要解析并验证它才能发送.下面是我现在的代码(C#,asp.net),如果有人对如何改进它有任何想法会很棒.
谢谢,
Annelie
private bool IsMobileNumberValid(string mobileNumber)
{
// parse the number
_mobileNumber = ParsedMobileNumber(mobileNumber);
// check if it's the right length
if (_mobileNumber.Length != 12)
{
return false;
}
// check if it contains non-numeric characters
if(!Regex.IsMatch(_mobileNumber, @"^[-+]?[0-9]*\.?[0-9]+$"))
{
return false;
}
return true;
}
private string ParsedMobileNumber(string number)
{
number = number.Replace("+", "");
number = number.Replace(".", "");
number = number.Replace(" ", "");
number = number.Replace("-", "");
number = number.Replace("/", "");
number = …Run Code Online (Sandbox Code Playgroud) 在覆盖Sitecore的链接提供商之后,我们的CPU达到峰值.我们正在重写GetItemUrl以获取某些类型模板的别名url,并且当访问网站的唯一内容是keepalive页面时,它会占用CPU的80%.
这是默认链接提供程序的配置行,可以正常工作:
<add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false" />
Run Code Online (Sandbox Code Playgroud)
这是我们的自定义链接提供程序的配置行,它会激活CPU:
<add name="sitecore"
type="Library.Pipelines.CustomLinkProvider, Library"
addAspxExtension="false"
alwaysIncludeServerUrl="false"
encodeNames="true"
languageEmbedding="never"
languageLocation="filePath"
shortenUrls="true"
useDisplayName="false" />
Run Code Online (Sandbox Code Playgroud)
CustomLinkProvider类:
public class CustomLinkProvider : LinkProvider
{
public override string GetItemUrl(Item item, UrlOptions options)
{
// check if item is factsheet or story, if it is then get the alias url
if (item.TemplateID == ItemConstants.Pages.Factsheet.TemplateID
|| item.TemplateID == ItemConstants.Pages.Story.TemplateID)
{
if (Sitecore.Context.Database != null)
{
if (SitecoreHelpers.HasAlias(item, Sitecore.Context.Database))
{
Item alias = SitecoreHelpers.GetAlias(item, …Run Code Online (Sandbox Code Playgroud) 我可能会在这里忽略一些明显的东西,但是可以在注册时使用用户名中的用户名返回Sitecore用户吗?
目前,用户名将显示为用户登录时输入的内容,但我希望能够获取原始字符串.
我正在使用 User user = User.FromName(domainUser, false);
更新: 这是我在Yan的优秀答案之后得到的:
// get the MembershipUser object normally by name
var initialUser = Membership.GetUser(domainUser, false);
if (initialUser != null)
{
// get the same MembershipUser by Id - in this case it retuns username in correct case
initialUser = Membership.GetUser(initialUser.ProviderUserKey, false);
}
// get the Sitecore user from the username in correct case
Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(initialUser.UserName, false);
Run Code Online (Sandbox Code Playgroud)
谢谢,
Annelie