mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
v0.1.0 & FreeSql.Repository
This commit is contained in:
parent
9222de0668
commit
204ab9f7d8
@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace efcore_to_freesql.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ValuesController : ControllerBase
|
||||
{
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
return new string[] { "value1", "value2" };
|
||||
}
|
||||
|
||||
// GET api/values/5
|
||||
[HttpGet("{id}")]
|
||||
public ActionResult<string> Get(int id)
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
|
||||
// POST api/values
|
||||
[HttpPost]
|
||||
public void Post([FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// PUT api/values/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// DELETE api/values/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
27
Examples/repository_01/Properties/launchSettings.json
Normal file
27
Examples/repository_01/Properties/launchSettings.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:54379/",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"repository_01": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:54383/"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql {
|
||||
|
@ -1,7 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.1.0</Version>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
|
||||
<PackageProjectUrl>https://github.com/2881099/FreeSql</PackageProjectUrl>
|
||||
<PackageTags>FreeSql ORM Repository</PackageTags>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FreeSql {
|
||||
public interface IReadOnlyRepository<TEntity> : IRepository
|
||||
|
@ -25,6 +25,9 @@ namespace FreeSql.Tests.MySql {
|
||||
|
||||
[Column(DbType = "varchar(200) not null", OldName = "title")]
|
||||
public string title222 { get; set; } = "10";
|
||||
|
||||
[Column(IsIgnore = true)]
|
||||
public DateTime ct { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -27,6 +27,9 @@ namespace FreeSql.Tests.Oracle {
|
||||
|
||||
[Column(DbType = "varchar2(200 char) not null", OldName = "title")]
|
||||
public string title2 { get; set; } = "10";
|
||||
|
||||
[Column(IsIgnore = true)]
|
||||
public DateTime ct { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -42,6 +42,10 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
|
||||
//[Column(DbType = "varchar(100) not null", OldName = "title122333aaa")]
|
||||
//public string titleaaa { get; set; } = "fsdf";
|
||||
|
||||
|
||||
[Column(IsIgnore = true)]
|
||||
public DateTime ct { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -31,6 +31,9 @@ namespace FreeSql.Tests.SqlServer {
|
||||
|
||||
[Column(DbType = "varchar(100) not null", OldName = "title122333aaa")]
|
||||
public string titleaaa { get; set; } = "fsdf";
|
||||
|
||||
[Column(IsIgnore = true)]
|
||||
public DateTime ct { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -27,6 +27,9 @@ namespace FreeSql.Tests.Sqlite {
|
||||
|
||||
[Column(DbType = "varchar(200) not null", OldName = "title2")]
|
||||
public string title3223 { get; set; } = "10";
|
||||
|
||||
[Column(IsIgnore = true)]
|
||||
public DateTime ct { get; set; } = DateTime.Now;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -16,7 +16,7 @@ namespace FreeSql.DataAnnotations {
|
||||
/// </summary>
|
||||
public string DbType { get; set; }
|
||||
|
||||
internal bool? _IsPrimary, _IsIdentity, _IsNullable;
|
||||
internal bool? _IsPrimary, _IsIdentity, _IsNullable, _IsIgnore;
|
||||
/// <summary>
|
||||
/// 主键
|
||||
/// </summary>
|
||||
@ -29,6 +29,10 @@ namespace FreeSql.DataAnnotations {
|
||||
/// 是否可DBNull
|
||||
/// </summary>
|
||||
public bool IsNullable { get => _IsNullable ?? false; set => _IsNullable = value; }
|
||||
/// <summary>
|
||||
/// 忽略此列,不迁移、不插入
|
||||
/// </summary>
|
||||
public bool IsIgnore { get => _IsIgnore ?? false; set => _IsIgnore = value; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库默认值
|
||||
|
@ -50,5 +50,12 @@ namespace FreeSql.DataAnnotations {
|
||||
_column.IsNullable = value;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 忽略此列,不迁移、不插入
|
||||
/// </summary>
|
||||
public ColumnFluent IsIgnore(bool value) {
|
||||
_column.IsIgnore = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.0.14</Version>
|
||||
<Version>0.1.0</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>打造 .NETCore 最方便的 ORM,DbFirst 与 CodeFirst 混合使用,提供从实体同步数据库,或者从数据库生成实体代码,支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库。</Description>
|
||||
|
@ -72,6 +72,7 @@ namespace FreeSql.Internal {
|
||||
if (attr._IsPrimary == null) attr._IsPrimary = trycol.IsPrimary;
|
||||
if (attr._IsIdentity == null) attr._IsIdentity = trycol.IsIdentity;
|
||||
if (attr._IsNullable == null) attr._IsNullable = trycol.IsNullable;
|
||||
if (attr._IsIgnore == null) attr._IsIgnore = trycol.IsIgnore;
|
||||
if (attr.DbDefautValue == null) attr.DbDefautValue = trycol.DbDefautValue;
|
||||
return attr;
|
||||
}
|
||||
|
@ -63,7 +63,9 @@ namespace FreeSql.Internal {
|
||||
IsIdentity = false,
|
||||
IsNullable = tp.Value.isnullable ?? true,
|
||||
IsPrimary = false,
|
||||
IsIgnore = false
|
||||
};
|
||||
if (colattr.IsIgnore) continue;
|
||||
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
|
||||
colattr.DbType = colattr.DbType.ToUpper();
|
||||
|
||||
@ -101,7 +103,17 @@ namespace FreeSql.Internal {
|
||||
}
|
||||
trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsPrimary == true).ToArray();
|
||||
if (trytb.Primarys.Any() == false) {
|
||||
trytb.Primarys = trytb.Columns.Values.Where(a => a.Attribute.IsIdentity == true).ToArray();
|
||||
trytb.Primarys = trytb.Columns.Values.Where(a => string.Compare(a.Attribute.Name, "id", true) == 0).ToArray();
|
||||
if (trytb.Primarys.Any() == false) {
|
||||
trytb.Primarys = trytb.Columns.Values.Where(a => string.Compare(a.Attribute.Name, $"{trytb.DbName}id", true) == 0).ToArray();
|
||||
if (trytb.Primarys.Any() == false) {
|
||||
trytb.Primarys = trytb.Columns.Values.Where(a => string.Compare(a.Attribute.Name, $"{trytb.DbName}_id", true) == 0).ToArray();
|
||||
if (trytb.Primarys.Any() == false) {
|
||||
var identcols = trytb.Columns.Values.Where(a => a.Attribute.IsIdentity == true).FirstOrDefault();
|
||||
if (identcols != null) trytb.Primarys = new[] { identcols };
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var col in trytb.Primarys)
|
||||
col.Attribute.IsPrimary = true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user