如何将图像类型添加到EF4 Code First Entity?我需要为缩略图添加一列.
public Image Thumbnail { get; set; }
Run Code Online (Sandbox Code Playgroud)
谢谢!
使用CTP4,我曾经能够执行以下操作(如ptrandem所示):
modelBuilder.IncludeMetadataInDatabase = false
Run Code Online (Sandbox Code Playgroud)
使用这行代码,EF不会在我的数据库中创建EdmMetadata表,也不会跟踪模型更改.
我无法在新的CTP5中找到实现这一目标的方法,所以现在每次更改模型时,我都会得到:
自创建数据库以来,支持"MyContext"上下文的模型已更改.手动删除/更新数据库,或使用IDatabaseInitializer实例调用Database.SetInitializer.例如,DropCreateDatabaseIfModelChanges策略将自动删除并重新创建数据库,并可选择使用新数据对其进行种子设定.
那么,是否每个人都知道CTP5中的IncludeMetadataInDatabase属性在哪里?谢谢.
将所有表格放在一个单独的edmx中会严重损害性能吗?我听说这是一个不好的做法,但这是在实体实现延迟加载之前.那么,既然我们有实体4,那么它是不是问题吗?
我计划通过扩展每个生成的实体的部分类来实现我的模型ICrud<ConcreteModel>.这与MVC3相结合应该可以消除任何耦合问题.
以前我在我的项目中使用了Entity Framework 4.0 CTP5(代码优先)和SQL Compact.我使用NuGet安装了以下软件包:
现在发布EF 4.1 RC时,我想将所有库更新到最新版本.NuGet feed不再包含SQLCE.4.0.8435.1的任何更新,但它有一个新包' SqlServerCompact - 4.0.8482.1 '(新包,而不是现有包的新版本).假设它刚刚重命名,我应该安装它.这样对吗?假设,是的.
NuGet也不包含"EFCodeFirst"和"EFCodeFirst.SqlServerCompact"包的任何更新.但它有一个新的' EntityFramework 4.1.10311.0 '包.
那么我应该安装什么?" EntityFramework 4.1.10311.0 "和" SqlServerCompact - 4.0.8482.1 "是否足以首先在SQL Compact中使用EF代码?
sql-server-ce entity-framework-4 nuget sql-server-ce-4 entity-framework-4.1
我有一个看起来像这样的查询:
IQueryable<Profile> profiles = from p in connection.Profiles
where profile.Email.Contains(txtSearch)
select p;
Run Code Online (Sandbox Code Playgroud)
我知道当它转换为SQL时它会使用a LIKE '%<value of txtSearch>%'但是如果txtSearch = "jon%gmail.com"它将它转换为`LIKE'%jon~%gmail.com%'.〜逃脱了中间的百分比,这是一张外卡.我该如何解决这个问题?我需要能够将通配符放入我的LINQ到EF搜索中.
我有一个通用的存储库,并希望实现一个通用的GetById方法.到目前为止,这是我的存储库界面:
public interface IRepository<T> where T : EntityObject
{
void Add(T entity);
void Delete(int id);
void Delete(T entity);
IEnumerable<T> Find(Expression<Func<T, bool>> predicate);
T SingleOrDefault(Expression<Func<T, bool>> predicate);
IEnumerable<T> GetAll();
T GetById(int id);
void Save();
T Single(Expression<Func<T, bool>> predicate);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Entity Framework 4.1.我发现的很多解决方案都是为IEntity类使用一个抽象基类接口,实体必须继承这个类才能执行Id查找.
我没有为所有类实现接口,而是尝试使用这段代码:
T entity = _objectSet.Where(
x => x.EntityKey.EntityKeyValues
.Select(v => v.Value.Equals(id)).Count() == 1).First();
Run Code Online (Sandbox Code Playgroud)
但是,当尝试使用该方法时,我收到一个异常:
The specified type member 'EntityKey' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
有人能告诉我如何让这个工作吗?
更新1
成员_objectContext和_context声明如下: …
我有一个实体数据模型,其中包含两个实体"角色"和"用户".我有一个导航属性,我有一个EntityDataSource和一个GridView.EntityDataSource指向Users实体并具有Include ="Roles"参数.
我在GridView中添加了一个BoundField,它指向RoleName,它是实体Roles的一个属性.但是,当我执行代码时,我得到上述错误.
我在另一个应用程序中成功使用了非常相似的代码 任何想法为什么这不起作用?
这是我的EntityDataSource:
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=pbu_checklistEntities"
DefaultContainerName="pbu_checklistEntities" EnableDelete="True"
EnableFlattening="False" EnableUpdate="True" EntitySetName="Users" Include="Role">
</asp:EntityDataSource>
Run Code Online (Sandbox Code Playgroud)
这是BoundField:
<asp:BoundField DataField="RoleName" HeaderText="Role" SortExpression="RoleName" />
Run Code Online (Sandbox Code Playgroud) vb.net asp.net linq-to-entities entity-framework entity-framework-4
我需要扩展我的EF部分类,因为我想添加一些功能来使用Oracle的序列,但是我真的不知道如何使用这个部分类的东西,我制作了一个单独的.cs文件并将其命名为一个我的自动生成的类如下:
namespace GlassStoreDAL
{
public partial class CAR
{
private int _sequences;
public int sequences
{
get { return _sequences; }
set { _sequences = value; }
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我认为,在我的BLL上 - 它引用了GlassStoreDAL - 我可以找到我的"序列"属性,但显然出现了问题,我将不胜感激.
这是我生成的部分类,我是否还有序列属性?
[EdmEntityTypeAttribute(NamespaceName="Model", Name="CAR")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class CAR : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new CAR object.
/// </summary>
/// <param name="id">Initial value of the ID property.</param>
public static CAR CreateCAR(global::System.Decimal id)
{
CAR cAR = new CAR();
cAR.ID …Run Code Online (Sandbox Code Playgroud) 我试图以下列方式执行EF更新,但继续收到此错误:
只有当属性的当前值为null时,才能设置EntityKey属性.
using (hydraEntities db = new hydraEntities())
{
YouUser = db.youusers.Include("address").Include("entity").Include("youusercontacts.contact").Include("youuserlogins").Include("youusernotes.note").Include("youusernotes.youuser.entity").Where( yu => yu.YOUUserId.Equals(YOUUserId)).First();
}
YouUser.entity.FirstName = txtFirstName.Text;
YouUser.entity.LastName = txtLastName.Text;
YouUser.address.AddressLine1 = txtAddressLine1.Text;
YouUser.address.AddressLine2 = txtAddressLine2.Text;
YouUser.address.City = txtCity.Text;
YouUser.address.State = ddlState.SelectedValue;
YouUser.address.Zipcode = txtZipcode.Text;
using (hydraEntities db = new hydraEntities())
{
db.youusers.AddObject(YouUser);
db.ObjectStateManager.ChangeObjectState(YouUser, System.Data.EntityState.Modified);
db.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
非常感谢我如何解决这个问题并执行上述声明.