LazyLoadingEnabled专门设置为true以防止相关实体在我正在使用的上下文中加载.
药物类别中有药物相关对象列表.
public class Drug
{
public virtual List<DrugIdentity> DrugIdentities { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如果我想要包含要加载的相关实体,则该类的特定配置设置密钥和hasmany关系.
public DrugConfiguration()
{
this.HasKey(d => d.DrugID);
this.HasMany(d => d.DrugIdentities).WithOptional(d => d.Drug).Map(d => d.MapKey("DrugID"));
}
Run Code Online (Sandbox Code Playgroud)
当使用linq查询加载Drug上下文时,对象显示它不包含相关的DrugIdentities.
context.Configuration.LazyLoadingEnabled = true;
var drugs = from d in context.Drug
where d.Active == true
select d;
Run Code Online (Sandbox Code Playgroud)
药物[0].药物身份数= 1
我认为药物[0] .DrugIdentities等于NULL,因为lazyloading设置为true?
我有一个路由器设置来接受任何与其中的“API”一词不匹配的 GET 请求。这是针对我的单页应用程序,因此我的 javascript 无法使用其路由的任何书签网址。
问题是每次我使用测试 url 刷新页面时都会失败。
网址:http://localhost:3000/my-test-url
第一次点击 url,我的索引页面加载。
第二次刷新页面,错误。
无法获取 /my-test-url
第三次刷新它有效,第四次失败,依此类推。
app.engine('html', cons.underscore);
app.set('view engine', 'html');
app.set('views', path.resolve(__dirname, '../client'));
// serve static content for the app from the "client" directory in the application directory
//express.static(path.join(__dirname, '../client')))
app.get(/^(?!.*\bapi\b).*$/ig, function(req, res) {
res.render('index');
});
app.listen(app.get('port'), function() {
console.log('Server up: http://localhost:' + app.get('port'));
});
Run Code Online (Sandbox Code Playgroud)
有没有什么东西可以在第一次工作后使请求保持打开状态?浏览器中的网络选项卡每次都显示相同的 URL,但交替显示 404 错误。任何建议表示赞赏。
更新,似乎有问题可能不是正则表达式,而是路由器每次如何解释它。当我设置这样的路线时:
app.get('*', function(req, res) {
console.log(req.route);
res.render('index');
});
Run Code Online (Sandbox Code Playgroud)
正如我所料,它似乎每次都有效。
我在请求应用程序上执行了一个简单的Cheerio解析。不知道为什么在尝试设置数组时会出现这个未定义的错误,但是我猜该值不存在。
var $ = cheerio.load(body);
var json = [
{ "range": "", "address": "", "state": "", "zip": "", "info": "" }
];
$('.findCourse').each(function (i, elem) {
// Range Name
console.log("iteration - ", i);
console.log("name - ", $(this).text().trim());
json[i].range = $(this).text().trim();
});
Run Code Online (Sandbox Code Playgroud)
这是我的控制台响应,它读取并设置它在已抓取的html中找到的前两个项目。
iteration - 0
name - Pollock's Ferry Hunting Club Inc.
iteration - 1
name - Eagle 1
Run Code Online (Sandbox Code Playgroud)
TypeError:无法设置未定义的属性“范围”
Run Code Online (Sandbox Code Playgroud)at Object.<anonymous> (/usr/local/node_app/server.js:30:31) at exports.each (/usr/local/node_app/node_modules/cheerio/lib/api/traversing.js:267:24) at Request.request.post.form.__EVENTTARGET [as _callback] (/usr/local/node_app/server.js:26:30) at Request.self.callback (/usr/local/node_app/node_modules/request/request.js:121:22) at Request.EventEmitter.emit (events.js:98:17) at Request.<anonymous> (/usr/local/node_app/node_modules/request/request.js:978:14) …