我想将Entity Framework 6集成到我们的系统中,但是有问题.
问题是:
我不能通过像[Table],[Column]这样的属性来映射函数.只有1个属性可用[DbFunction],它需要*.edmx文件.
我可以在*.edmx文件中映射函数,但这意味着我不能使用实体的属性映射:[Table],[Column].必须在*.edmx或属性中填充映射.
我尝试通过以下代码创建DbModel并添加函数:
public static class Functions
{
[DbFunction("CodeFirstNamespace", "TestEntity")]
public static string TestEntity()
{
throw new NotSupportedException();
}
}
public class MyContext : DbContext, IDataAccess
{
protected MyContext (string connectionString)
: base(connectionString, CreateModel())
{
}
private static DbCompiledModel CreateModel()
{
var dbModelBuilder = new DbModelBuilder(DbModelBuilderVersion.Latest);
dbModelBuilder.Entity<Warehouse>();
var dbModel = dbModelBuilder.Build(new DbProviderInfo("System.Data.SqlClient", "2008"));
var edmType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String);
var payload =
new EdmFunctionPayload
{
Schema = "dbo",
ParameterTypeSemantics = ParameterTypeSemantics.AllowImplicitConversion, …Run Code Online (Sandbox Code Playgroud) c# entity-framework sql-function ef-code-first entity-framework-6
rowversion(时间戳)数据类型的正确类型是什么?
我知道它是8个字节,但我找不到MSDN中的链接,它告诉它是有符号还是无符号长.
我应该使用哪些代码,甚至重要吗?
byte[] SqlTimeStamp;
long longConversion;
longConversion = BitConverter.ToInt64(SqlTimeStamp,0);
TimeStamp = BitConverter.GetBytes(longConversion);
ulong ulongConversion;
ulongConversion = BitConverter.ToUInt64(SqlTimeStamp,0);
TimeStamp = BitConverter.GetBytes(ulongConversion);
Run Code Online (Sandbox Code Playgroud) 我应该如何rowversion使用Entity Framework 比较字段?我有一个表有一个rowversion列,我想从表中获取行版本高于指定值的数据.
byte[] rowversion = ... some value;
_context.Set<T>().Where(item => item.RowVersion > rowVersion);
Run Code Online (Sandbox Code Playgroud)
这行不起作用,它抛出错误:
不能应用于'byte []'和'byte []'类型的操作数
知道如何比较rowversionc#/ EF中的字段吗?
RowId我的SQL Server数据库中有一个带有timestamp column()的表.
我想根据此时间戳查询新行.SQL查询如下
SELECT *
FROM [MyTable]
where RowId>=0x0000000000A99B06
Run Code Online (Sandbox Code Playgroud)
0x0000000000A99B06 是上一个查询的最大时间戳值.
如何使用Entity Framework数据库优先进行此类查询?RowId映射到byte[]属性,我不知道如何比较LINQ查询中的字节数组.