在下面剪断我尝试使用获取数据Anonymous Projection,我想不跟踪entities获取的数据.
注意:我已经完成了现有的堆栈问题,但无法为我找到有效的解决方案
using (var db = new Entities())
{
db.Configuration.LazyLoadingEnabled = false;
db.Configuration.ProxyCreationEnabled = false;
var myprojection = db.Table1
.AsNoTracking()
.Include(gh=>gh.Table2) //Update
.Include(gh=>gh.Table3) //Update
.Select(x => new
{
table1= x,
table2= x.Table2.Where(g => Some Condition),
table3= x.Table3.Where(g=>Some Condition)
})
.ToList();
var result = myprojection.Select(g =>g.table1).FirstOrDefault();
}
Run Code Online (Sandbox Code Playgroud)
当我使用
AsNoTracking()内部表格中的数据(表格2,3)在此行的转换过程中丢失var result = myprojection.Select(g =>g.table1).FirstOrDefault();
编辑
如果我删除
AsNoTracking()一切正常.
1)如何使用projection和AsNoTracking在实体框架是否正确?
2)删除此查询的跟踪的任何其他选项?
有没有可能的解决方法?
public EmployeeDTO AuthenticateEmployee(string username, string password)
{
try
{
var userLogin = UnitOfWork.UserLoginRepository.Get(x => x.UserName == username).FirstOrDefault();
if (userLogin == null)
return null;
else
{
var userStore = new UserStore<IdentityUser>();
var userManager = new UserManager<IdentityUser>(userStore);
// this throws an error.
var user = userManager.Find("username", "password");
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果有误:
无法从程序集'EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'加载类型'System.ComponentModel.DataAnnotations.Schema.IndexAttribute'.
我使用的是EF 6.0,Microsoft.AspNet.Identity.EntityFrameworkVer 2.0.
我无法使用EF执行任何操作使用Identity我有什么需要做的,我的EDMX在另一个类库中.我认为这是一个DLL问题.
请帮我使用EF的身份.
我已经通过了Msdn
我首先使用数据库,我有一个switch看起来像这样的语句:
switch (site)
{
case Site.One:
using (OneContext one = new OneContext())
return one.OrganizationObjects.SingleOrDefault(x => x.u_Name == orgName)?.g_org_id;
case Site.Two:
using (TwoContext two = new TwoContext())
return two.OrganizationObjects.SingleOrDefault(x => x.u_Name == orgName)?.g_org_id;
default:
throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
两个数据库非常相似,几乎都有相同的模型.
如果我删除"两个"EDMX文件并注释掉条件,那么OneContext可以正常工作.
如果我将TwoContext EDMX文件添加到项目并再次运行代码,则"OneContext"代码在尝试查询时失败OrganizationObjects.
我确保每个上下文都使用正确的连接字符串,但仍会出现此错误:
我们在Android和IOS上使用Parse进行推送通知,效果很好!
我正在使用Windows 8.1应用程序,但无法使其正常运行.该应用程序是一个用javascript/html/css开发的通用应用程序.
我按照本指南在javascript项目中使用解析dll. https://parse.com/questions/windows-8-javascript-app-push-notifications
在我的应用程序启动时(在onactivated事件中)引用并调用我的新项目中的辅助方法.
public void InitializeParse(string appId, string key)
{
ParseClient.Initialize(appId, key);
}
public void SubscribeToParse()
{
ParsePush.SubscribeAsync("");
}
Run Code Online (Sandbox Code Playgroud)试过上面.Net-key和Client key上面的两个.
我可以看到手机注册到Parse,因为我可以选择仅在推送时使用Windows段.
设备数量大于0.
发送的推送次数始终为0.
任何帮助表示赞赏?
onactivated事件,我是否必须在其他地方调用方法?javascript windows parse-platform windows-phone-8 win-universal-app
我有一个带有ListView的Windows Phone 8.1项目,其后面的c#代码填充了它的itemssource.它工作,但我最终在单行文本块之间有空格.我已经尝试在文本块上设置高度,它位于列表视图内部.我尝试设置一个ItemContainerStyle,将高度绑定到文本块的高度,但它不起作用.
如果我将TextBlock的文本设置为Actual Height绑定,我得到0,所以我一定做错了.我很确定它与ListViewItems的高度有关,但由于它们是从代码填充的,我无法弄清楚如何让它们做我想做的事情.我也尝试切换到列表的ItemsControl但它似乎没有滚动和工作.这是Listview的XAML:
<ListView x:Name="TheList" IsHoldingEnabled="True"
ItemsSource="{Binding items}"
Loaded="WhenListViewBaseLoaded"
ContinuumNavigationTransitionInfo.ExitElementContainer="True"
IsItemClickEnabled="True">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Height" Value="{Binding ElementName=txtBibleText, Path=ActualHeight}"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid x:Name="ItemTemplateGrid" Holding="ListViewItem_Holding" Background="Blue">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Share"
Click="ShareFlyoutItem_Click" />
<MenuFlyoutItem Text="Add to Sharing"
Click="AddSharingFlyoutItem_Click" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<Grid x:Name="gridText">
<TextBlock x:Name="txtBibleText"
FontSize="{Binding TheFontSize}"
Grid.Column="1"
VerticalAlignment="Top"
HorizontalAlignment="Left"
TextWrapping="Wrap"
Margin="0,0,0,0" FontFamily="Global User Interface">
<Run Text="{Binding VerseNumber}"/>
<Run Text="{Binding BibleText}"/>
</TextBlock>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
填充ListView的代码背后:
XDocument loadedData = XDocument.Load(TranlationFilePath);
var data = from query in …Run Code Online (Sandbox Code Playgroud) 请帮我处理这种情况:
我故意关掉
AutoDetectChangesEnabled,我也故意加载我的实体AsNoTracked()。在这种情况下,我无法更新多对多关系:
这是更新方法的代码:
public void Update(User user)
{
var userRoleIds = user.Roles.Select(x => x.Id);
var updated = _users.Find(user.Id);
if (updated == null)
{
throw new InvalidOperationException("Can't update user that doesn't exists in database");
}
updated.Name = user.Name;
updated.LastName = user.LastName;
updated.Login = user.Login;
updated.Password = user.Password;
updated.State = user.State;
var newRoles = _roles.Where(r => userRoleIds.Contains(r.Id)).ToList();
updated.Roles.Clear();
foreach (var newRole in newRoles)
{
updated.Roles.Add(newRole);
}
_context.Entry(updated).State = EntityState.Modified;
}
Run Code Online (Sandbox Code Playgroud)
所有简单的字段,例如
Name,LastName都已更新。 …
我使用以下 Linq 查询:
var projectList = from p in dbContext.vw_Projektkontrolle
where p.TXT_Adress1.Contains(filterTxt)
orderby p.TXT_Name
select p;
Run Code Online (Sandbox Code Playgroud)
我projectList的总是空的。在调试中我可以看到,filterTxt例如“testcompany”。
EF 6 中是否仍在使用 contains 方法或是否有任何解决方法?
我将filterTxt通过 Form Post传递给我的 MVC 应用程序中的 Action 方法。
如何解决这个问题。
编辑:当我只使用一个
charf.ex: "a" as时它有效filterTxt。但是
TXT_Adress1和filterTxt都被声明为字符串
我已经开始ConfigureAwait(false)与所有异步sql对象一起使用。
connection.OpenAsync().ConfigureAwait(false);
cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)
但我担心的是,这种方法会产生任何影响吗?
因为这将在线程池中运行,而线程池是一个独立的线程,所以我不确定如果不在单个线程上运行会带来什么后果。
我们的应用程序是wcf服务,它将并行处理1000条记录。
如果有人帮助确定可能存在问题的业务场景,那将是有帮助的。
谢谢
我知道onSelectionChange()通过 mat-autocomplete 的 mat-option 我可以在选择一个选项时做一些事情,但我想要的是自动完成将 mat-option 的值添加到输入而不是替换其内容。
例子:
我如何在不保留表单值的标签并存储其先前值并将其放回原处的情况下完成此操作(因为这似乎是一个糟糕的解决方法)?
<mat-form-field class="w-100">
<textarea [matAutocomplete]="auto" [value]="hello" matInput></textarea>
<mat-autocomplete #auto="matAutocomplete" >
<mat-option [value]="world">
world
</mat-option>
</mat-autocomplete>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud) 如何在 angular 2 中进行并行调用 HTTP get 或 post 调用?
我对一个愈伤组织的响应有 2 个服务呼叫必须拨打另一个电话。
有人可以建议我如何使用错误处理方案调用 make 这些并行调用吗?
c# ×6
.net ×2
angular ×2
linq ×2
angular-http ×1
anonymous ×1
async-await ×1
contains ×1
datatemplate ×1
javascript ×1
listview ×1
many-to-many ×1
rxjs ×1
sql ×1
typescript ×1
windows ×1
xaml ×1