我在c#中理解存储库模式.当我研究通用存储库模式时,我很困惑.它有很多重复.我对这种模式有一些疑问.
我使用实体框架代码第一种方法,我有两个模型类
学生
教师
如果我有一个通用接口,我将使用多少通用接口
public interface IRepository<TEntity>
{
IQueryable<TEntity> FindAll(Expression<Func<TEntity, bool>> where = null);
TEntity FindOne(Expression<Func<TEntity, bool>> where = null);
}
Run Code Online (Sandbox Code Playgroud)
因此,此接口可用于两个模型类.如果Student类有更多的方法可以定义这些方法?例如
public class StudentRepo<TEntity> : IRepository<TEntity> where TEntity : class
{
public virtual IQueryable<TEntity> FindAll(Expression<Func<TEntity, bool>> where = null)
{
return null != where ? Context.Set<TEntity>().Where(where) : Context.Set<TEntity>();
}
public virtual TEntity FindOne(Expression<Func<TEntity, bool>> where = null)
{
return FindAll(where).FirstOrDefault();
}
public void update()
{
}
public int FindId()
{
}
}
Run Code Online (Sandbox Code Playgroud)
所以我添加了两个新方法update(),FindId() …
我想在最近几天解决这个问题.
首先,我在代理服务器后面工作,我使用Cntlm建立连接,我尝试在我的Visual Studio Online帐户上创建一个小存储库,一切都按预期工作,我能够克隆和推送.
我创建了另一个存储库,这次更大(整个回购大约是800MB),当我试图推送时.它需要我通过身份验证周期,然后它就会挂起(我已经将它挂了24小时而没有任何反应).postBuffer正如其他地方所建议的那样,我已经将git 增加到了524288000,但这并没有帮助.
我已经设定了更多
GIT_CURL_VERBOSE=1
Run Code Online (Sandbox Code Playgroud)
然后当我跑:
git push origin master -v
Run Code Online (Sandbox Code Playgroud)
这是它被卡住的地方:
> POST /DefaultCollection/_git/PROJex/git-receive-pack HTTP/1.1
Authorization: Basic ZGRpbWl0cm92OkQxbxxxxxx
User-Agent: git/1.9.2.msysgit.0
Host: [user].visualstudio.com
Accept-Encoding: gzip
Content-Type: application/x-git-receive-pack-request
Accept: application/x-git-receive-pack-result
Content-Length: 37423253
* Connection #1 to host localhost left intact
Run Code Online (Sandbox Code Playgroud)
我看到内容长度明显大于小型回购.我还应该注意到有500多个提交日志.
现在我认为它可能是一个代理问题,所以我在没有代理的情况下在不同的网络上尝试了它,我得到了相同的结果.除了http(s)之外的任何内容都不是我的设置中的选项.
pgadmin4我正在尝试在 Arch Linux 上安装。这是我所做的:
sudo pacman -S pgadmin4
Run Code Online (Sandbox Code Playgroud)
然后我简单地尝试运行pgadmin4并得到以下错误:
"An error occurred initialising the pgAdmin 4 server:\n\nFailed to launch the application server, server thread exiting."
Run Code Online (Sandbox Code Playgroud)
然后,我尝试pgAdmin4.py直接运行:
"An error occurred initialising the pgAdmin 4 server:\n\nFailed to launch the application server, server thread exiting."
Run Code Online (Sandbox Code Playgroud)
我收到以下堆栈跟踪错误:
Traceback (most recent call last):
File "/usr/lib/pgadmin4/web/pgAdmin4.py", line 35, in <module>
import config
File "/usr/lib/pgadmin4/web/config.py", line 25, in <module>
from pgadmin.utils import env, IS_WIN, fs_short_path
File "/usr/lib/pgadmin4/web/pgadmin/__init__.py", line 28, in <module>
from …Run Code Online (Sandbox Code Playgroud) 我的Java有点生疏(过去几年一直在做C#).我也希望这不是一个非常主观的问题.
无论如何说我上课了Person(是的,有点陈词滥调,我知道),没有行为(C#版本):
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
// say 10+ properties
}
Run Code Online (Sandbox Code Playgroud)
等效的Java版本将如何?我知道我可以写一堆getter和setter(但是我说有10多个属性),感觉就像很多样板.这样做是不好的做法:
public class Person {
public String name;
public int age;
// rest of the stuff here
}
Run Code Online (Sandbox Code Playgroud)
我对此感到有点不安.我意识到没有"正确答案"但是,我对一般惯例和最佳实践更感兴趣.
我正在建立一个新闻网站。目前,我使用 MySQL 作为主要数据存储,并使用 Redis 来维护用户主页提要的文章列表。当用户点击主页上的一篇文章时,我会连接到 MySQL 以获取文章的主要内容、评论和相关内容。
如果我将所有文章数据存储在 Redis 中是最佳实践吗?我的意思是,我不是连接MySQL来获取文章的全部内容,而是将文章的主要内容存储在Redis中,这样可以提高性能?
我在客户端有以下代码:
fetch("/music/index", { headers: { "Content-Type": "application/json" } })
.then(response => {
if (!response.ok) {
throw response;
}
return response.json();
})
.then(json => {
console.log("Done! It's all good");
})
.catch(response => console.log(response));
Run Code Online (Sandbox Code Playgroud)
不幸的是,这甚至没有到达MusicController(服务器端),它看起来如下(为了说明这一点而进行了简化):
[Authorize]
public class MusicController : Controller {
public async Task<IActionResult> Index() {
IEnumerable<Song> songs = await _songsRepository.GetAll();
return Json(songs);
}
}
Run Code Online (Sandbox Code Playgroud)
从我在开发者控制台中看到的我被重定向到 /Account/Login?returnUrl...
同时,使用 jquery api,一切似乎都正常:
$.get("/music/index")
.done(json => console.log("Done! It's all good"))
.fail(error => console.log(error));
Run Code Online (Sandbox Code Playgroud)
我怀疑我没有正确设置我的标题?不确定在网上找不到任何东西。此外,此(或非常相似)代码用于在以前(非核心)版本的 ASP.NET 中工作。
好的,这是我的问题.我理解OAuth协议的过程,但是我对它有些困惑.我正在尝试利用DotNetOpenAuth.Here是我无法得到的东西.假设用户(新用户)尝试使用Twitter登录我的网站.这个过程是这样的(如果我错了,请随时纠正我):
到现在为止还挺好.现在这里是令人困惑的部分.用户注销.然后回来并尝试再次使用Twitter进行身份验证.我如何确定他的访问令牌,如果在获得访问令牌之前我无法获得他的身份?我让他在数据库中,但是在他再次完成相同的步骤之前,我无法确定他是谁.我确定我错过了一些东西,如果你指出它我会很感激的.我知道IConsumerTokenManager,我尝试对InMemoryTokenManager进行逆向工程,看看它是如何工作的,但目前还不清楚.
我已经创建了一个代码,用于更新/编辑连接到MS Access的C#程序的计算机/电子产品的详细信息.以下是代码:
OleDbCommand cmd = new OleDbCommand("UPDATE Available SET ProductType = '" + newAvailable.ProductType + "', Brand = '"+ newAvailable.Brand + "', Model = '" + newAvailable.Model + "', SerialNo = '" + newAvailable.SerialNo + "', Remarks = '" + newAvailable.Remarks + "', RAM = '" + newAvailable.RAM + "', HDD = '" + newAvailable.HDD + "', ODD = '" + newAvailable.ODD + "', VideoCard = '" + newAvailable.VideoCard + "', PS = '" + newAvailable.PS + "' WHERE AvailableID …Run Code Online (Sandbox Code Playgroud) 因此,我在Java中有一个递归方法来获取'n'的斐波纳契数 - 我唯一的问题是:时间复杂度是多少?我认为这是O(2 ^ n),但我可能会弄错?(我知道迭代更好,但这是一个练习)
public int fibonacciRecursive(int n)
{
if(n == 1 || n == 2) return 1;
else return fibonacciRecursive(n-2) + fibonacciRecursive(n-1);
}
Run Code Online (Sandbox Code Playgroud) 我有一个名为frmMain的表单,其中我有以下功能:
public void openFullScreen(String id,String content)
{
frmEditor Editor = new frmEditor();
Editor.WindowState = FormWindowState.Maximized;
Editor.Content = content;
Editor.ID = id;
Editor.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
在Editor.cs中我使用以下代码:
private void btnClose_Click(object sender, EventArgs e)
{
Object content = browserEditor.Document.InvokeScript("getContent");
if (content != null)
{
object[] args = new object[2];
args[0] = content.ToString();
args[1] = _id;
AppDomain.CurrentDomain.SetData("EditorContent", args);
this.Close();
//browserEditor.Document.InvokeScript("setEditorContent",args)
}
}
Run Code Online (Sandbox Code Playgroud)
关闭frmEditor我想告诉frmMain frmEditor现在关闭了,知道我必须显示某个值.我该如何检查?
c# ×5
java ×2
archlinux ×1
asp.net ×1
asp.net-core ×1
azure-devops ×1
conventions ×1
fibonacci ×1
git ×1
javascript ×1
jquery ×1
linux ×1
methods ×1
ms-access ×1
oauth ×1
oledb ×1
pgadmin-4 ×1
python ×1
python-3.x ×1
recursion ×1
redis ×1
winforms ×1